package com.huikeportal.service.impl;

import java.lang.reflect.Field;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huikeportal.dao.FootfallGlobalMapper;
import com.huikeportal.dao.UserSiteHistoryMapper;
import com.huikeportal.model.AllIndexModel;
import com.huikeportal.model.IndexOrderModel;
import com.huikeportal.model.PrivilegeUsersSite;
import com.huikeportal.model.RankingData;
import com.huikeportal.model.ReportGraphData;
import com.huikeportal.model.ReportSiteDay;
import com.huikeportal.model.SiteAllInfo;
import com.huikeportal.model.SiteRelation;
import com.huikeportal.model.TodayIndexes;
import com.huikeportal.model.UserInfo;
import com.huikeportal.model.UserSiteHistory;
import com.huikeportal.model.WordBook;
import com.huikeportal.service.CommonService;
import com.huikeportal.service.FootfallGlobalService;
import com.huikeportal.service.LoginService;
import com.huikeportal.service.MemcachedService;

/** 
 * 2015-9-7 
 * 客流统计-全局分析-service实现
 * author:wenyp 
 */

@Service("FootfallGlobalService")
public class FootfallGlobalServiceImpl implements FootfallGlobalService {
	
	
	@Autowired
	private FootfallGlobalMapper footfallGlobalMapper;
	
	@Autowired
	private UserSiteHistoryMapper userSiteHistoryMapper;
	
	@Autowired
	private LoginService loginService;
	
	@Autowired
	private MemcachedService memcachedService;
	
	@Autowired
	private CommonService commonService;

	
	
	public List<ReportSiteDay> selectTableByCondition(HashMap<String, Object> map)  throws Exception{
		List<ReportSiteDay> resultList=new ArrayList<ReportSiteDay>();
		resultList =footfallGlobalMapper.selectTableByCondition(map);
		return resultList;
	};
	
	/**
	 * 递归取父id
	 * @param siteList
	 * @param siteID
	 * @return
	
	private List<String> getHighSiteId(List<String> siteList,String siteID){
		SiteRelation siteRelation=footfallGlobalMapper.selectSiteRelationByChildId(siteID);
		String highSiteID="";
		switch(1){
		case 1:
			if(siteRelation.getParent600()!=null&&!"".equals(siteRelation.getParent600())){
				highSiteID=siteRelation.getParent600(); break;}
		case 2:
			if(siteRelation.getParent500()!=null&&!"".equals(siteRelation.getParent500())){
				highSiteID=siteRelation.getParent500(); break;}
		case 3:
			if(siteRelation.getParent400()!=null&&!"".equals(siteRelation.getParent400())){
				highSiteID=siteRelation.getParent400(); break;}
		case 4:
			if(siteRelation.getParent300()!=null&&!"".equals(siteRelation.getParent300())){
				highSiteID=siteRelation.getParent300(); break;}
		case 5:
			if(siteRelation.getParent200()!=null&&!"".equals(siteRelation.getParent200())){
				highSiteID=siteRelation.getParent200(); break;}
		case 6:
			if(siteRelation.getParent100()!=null&&!"".equals(siteRelation.getParent100())){
				highSiteID=siteRelation.getParent100(); break;}
		default:
			 break;
		}
		
		if(!"".equals(highSiteID)){
			siteList.add(highSiteID);
			siteList=getHighSiteId(siteList,highSiteID);
			return siteList;
		}else{
			return siteList;
		}
	} */
	
	public List<String> getHighSiteId(List<String> siteList,String siteID){
		
		SiteRelation siteRelation=footfallGlobalMapper.selectSiteRelationByChildId(siteID);
		switch(1){
		case 1:
			if(siteRelation.getParent600()!=null&&!"".equals(siteRelation.getParent600())){
				siteList.add(siteRelation.getParent600());}
		case 2:
			if(siteRelation.getParent500()!=null&&!"".equals(siteRelation.getParent500())){
				siteList.add(siteRelation.getParent500());}
		case 3:
			if(siteRelation.getParent400()!=null&&!"".equals(siteRelation.getParent400())){
				siteList.add(siteRelation.getParent400());}
		case 4:
			if(siteRelation.getParent300()!=null&&!"".equals(siteRelation.getParent300())){
				siteList.add(siteRelation.getParent300());}
		case 5:
			if(siteRelation.getParent200()!=null&&!"".equals(siteRelation.getParent200())){
				siteList.add(siteRelation.getParent200());}
		case 6:
			if(siteRelation.getParent100()!=null&&!"".equals(siteRelation.getParent100())){
				siteList.add(siteRelation.getParent100());}
		default:
			 break;
		}
			return siteList;
	}
	
	
	/**
	 * 根据场所id取上级场所id，最后拼接成 集团-广场-区域-楼层-店铺 这种字符串
	 */
	public String getSiteNames(String siteID){
		SiteAllInfo siteAllInfo1= footfallGlobalMapper.selectSiteAllInfoById(siteID);
		//如果是集团
		if(siteAllInfo1!=null && siteAllInfo1.getType()==100){
			String siteNames = getSiteName(siteID);
			return siteNames;
		}else if(siteAllInfo1!=null && siteAllInfo1.getType()==300){//如果是广场
			String siteNames = getSiteName(siteID);
			return siteNames;
			/**
			List<String> siteList = new ArrayList<String>();
			siteList.add(siteID);
			siteList=getHighSiteId(siteList,siteID);
			Collections.reverse(siteList);
			String siteNames="";
			for(String siteId:siteList){
				SiteAllInfo siteAllInfo= footfallGlobalMapper.selectSiteAllInfoById(siteId);
				if(siteAllInfo!=null && siteAllInfo.getType()==100){
					siteNames=siteNames+getSiteName(siteId)+" - ";
				}
			}
			String lastSiteId = siteList.get(siteList.size()-1);
			siteNames=siteNames+getSiteName(lastSiteId);
			return siteNames;
			 */
		}else{
			//如果是广场
			List<String> siteList = new ArrayList<String>();
			siteList.add(siteID);
			siteList=getHighSiteId(siteList,siteID);
			Collections.reverse(siteList);
			String siteNames="";
			for(String siteId:siteList){
				SiteAllInfo siteAllInfo= footfallGlobalMapper.selectSiteAllInfoById(siteId);
				if(siteAllInfo!=null && siteAllInfo.getType()==300){
					siteNames=siteNames+getSiteName(siteId)+" - ";
				}
			}
			String lastSiteId = siteList.get(siteList.size()-1);
			siteNames=siteNames+getSiteName(lastSiteId);
			return siteNames;
		
		}
	}
	
	/**获取任意下级场所*/
	
	public	SiteAllInfo getAnyLowerSite(SiteAllInfo siteAllInfo,int type){
		SiteAllInfo siteAllInfoResult=null;
		
		HashMap<String, Object> map=new HashMap<String, Object>();
		int  parentType= siteAllInfo.getType();
		String parent="Parent" + Integer.toString(parentType);
		map.put("parent", parent);
		String siteId=siteAllInfo.getSiteid();
		map.put("siteId", siteId);
		List<SiteRelation> siteRelationList=footfallGlobalMapper.getLowerSite(map);
		for(int m=0;m<siteRelationList.size();m++){
			SiteRelation siteRelation=siteRelationList.get(m);
			SiteAllInfo rsiteAllInfo=footfallGlobalMapper.selectSiteAllInfoById(siteRelation.getId());
			if(rsiteAllInfo.getType()<=type){
				if(rsiteAllInfo.getType()==type){
					siteAllInfoResult=rsiteAllInfo;
					break;
				}else{
					siteAllInfoResult=getAnyLowerSite(rsiteAllInfo,type);
				}
			}
		}
		return siteAllInfoResult;
	}
	
	
	/**
	 * @author wyp
	 * 根据登录信息查询场所信息
	 * @throws Exception 
	 */
	
	public SiteAllInfo selectSiteByUserId(UserInfo userInfo,String siteType) throws Exception{
		
		SiteAllInfo resultSiteAllInfo=new SiteAllInfo();
		//依据登陆用户信息查询用户场所
		List<PrivilegeUsersSite> privilegeUsersSite= (List<PrivilegeUsersSite>) footfallGlobalMapper.selectUsersSiteByUser(userInfo);
		
		if(siteType!=null &&siteType.equals("100")){//获取集团场所
			List<SiteAllInfo> siteAllInfoList =loginService.getJtSiteList(userInfo);
			if(siteAllInfoList!=null&&siteAllInfoList.size()!=0){
				resultSiteAllInfo=siteAllInfoList.get(0);
			}
			
		}else if(siteType!=null &&siteType.equals("300")){//获取广场场所
			List<SiteAllInfo> siteAllInfoList =loginService.getGcSiteList(userInfo);
			if(siteAllInfoList!=null&&siteAllInfoList.size()!=0){
				resultSiteAllInfo=siteAllInfoList.get(0);
			}
		}else if(siteType!=null &&siteType.equals("400")){//获取区域场所
			List<SiteAllInfo> siteAllInfoList =loginService.getQySiteList(userInfo);
			if(siteAllInfoList!=null&&siteAllInfoList.size()!=0){
				resultSiteAllInfo=siteAllInfoList.get(0);
			}
		}else if(siteType!=null &&siteType.equals("500")){//获取楼层场所
			List<SiteAllInfo> siteAllInfoList =loginService.getLcSiteList(userInfo);
			if(siteAllInfoList!=null&&siteAllInfoList.size()!=0){
				resultSiteAllInfo=siteAllInfoList.get(0);
			}
		}else if(siteType!=null &&siteType.equals("600")){//获取店铺场所
			List<SiteAllInfo> siteAllInfoList =loginService.getDpSiteList(userInfo);
			if(siteAllInfoList!=null&&siteAllInfoList.size()!=0){
				resultSiteAllInfo=siteAllInfoList.get(0);
			}
		}else{//获取通道场所
			SiteAllInfo	siteAllInfo=footfallGlobalMapper.selectSiteAllInfoByUsersSite(privilegeUsersSite.get(0));
			if(siteAllInfo.getType()==700){
				resultSiteAllInfo=siteAllInfo;
			}else {
				resultSiteAllInfo=getAnyLowerSite(siteAllInfo, 700);
			}
		}
		return resultSiteAllInfo;
	};
	
	 /** 
     * 根据开始时间和结束时间返回时间段内的日期时间集合 
     *  
     * @param beginDate 
     * @param endDate 
     * @return List 
     */  
    public  List<String> getHoursBetweenTwoDate(String begin, String end) {
    
        List<String> lDate = new ArrayList<String>();  
        for(int i = 0;i <= 23;i++){
        	String hh = begin+" ";
        	if(i<10){
        		hh= hh+"0"+i+":00";
        	}else{
        		hh= hh+i+":00";
        	}
        	lDate.add(hh);
        }
        return lDate;  
    }
	
    /** 
     * 根据开始时间和结束时间返回时间段内的日期时间集合 
     *  
     * @param beginDate 
     * @param endDate 
     * @return List 
     */  
    public  List<String> getDatesBetweenTwoDate(String begin, String end) {
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    	Date beginDate =null;	
    	Date endDate =null;
    	try {
			beginDate = sdf.parse(begin);
			endDate = sdf.parse(end);
		} catch (ParseException e) {
			e.printStackTrace();
		}
        List<String> lDate = new ArrayList<String>();  
        lDate.add(sdf.format(beginDate));// 把开始时间加入集合  
        Calendar cal = Calendar.getInstance();  
        // 使用给定的 Date 设置此 Calendar 的时间  
        cal.setTime(beginDate);  
        boolean bContinue = true;  
        while (bContinue) {  
            // 根据日历的规则，为给定的日历字段添加或减去指定的时间量  
            cal.add(Calendar.DAY_OF_MONTH, 1);  
            // 测试此日期是否在指定日期之后  
            if (endDate.after(cal.getTime())||endDate.equals(cal.getTime())) {  
                lDate.add(sdf.format(cal.getTime()));  
            } else {  
                break;  
            }  
        }  
//        lDate.add(sdf.format(endDate));// 把结束时间加入集合  
        return lDate;  
    }
    
	/**
	 * 根据开始和结束年份和周，算出之间的周list
	 * 给开始时间加一周，如果大于等于结束时间加入list。
	 * @param beginYear
	 * @param beginWeek
	 * @param endYear
	 * @param endWeek
	 * @return List<String>
	 */
    public  List<String> getWeeksBetweenTwoWeek(String beginYear,String beginWeek,String endYear, String endWeek) {  
    	
    	Calendar calBegin = Calendar.getInstance();
    	calBegin.set(Calendar.YEAR,Integer.parseInt(beginYear));
    	calBegin.set(Calendar.WEEK_OF_YEAR, Integer.parseInt(beginWeek));
    	calBegin.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); 
    	
    	Calendar calEnd = Calendar.getInstance();
    	calEnd.set(Calendar.YEAR,Integer.parseInt(endYear));
    	calEnd.set(Calendar.WEEK_OF_YEAR, Integer.parseInt(endWeek));
    	calEnd.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); 
    	
    	List<String> lDate = new ArrayList<String>();  
    	//加入开始时间
    	lDate.add(String.valueOf(calBegin.get(Calendar.YEAR))+String.valueOf(calBegin.get(Calendar.WEEK_OF_YEAR)));
    	
    	 boolean bContinue = true;
    	 while (bContinue) {
    		 calBegin.add(Calendar.WEEK_OF_YEAR, 1);
    		 calBegin.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); 
    		 if(calEnd.after(calBegin)||calEnd.equals(calBegin)){
    			 lDate.add(String.valueOf(calBegin.get(Calendar.YEAR))+String.valueOf(calBegin.get(Calendar.WEEK_OF_YEAR)));
    		 }else{
    			 break;
    		 }
    	 }
    	 //加入结束时间
//    	 lDate.add(String.valueOf(calEnd.get(Calendar.YEAR))+String.valueOf(calEnd.get(Calendar.WEEK_OF_YEAR)));
    	
        return lDate;  
    }
    
    /**
     * 根据开始和结束年份和月，算出之间的月list
     * @param beginYear
     * @param beginMonth
     * @param endYear
     * @param endMonth
     * @return
     */
    public  List<String> getMonthsBetweenTwoMonth(String beginYear,String beginMonth,String endYear, String endMonth) {  
    	
    	Calendar calBegin = Calendar.getInstance();
    	calBegin.set(Calendar.YEAR,Integer.parseInt(beginYear));
    	calBegin.set(Calendar.MONTH, Integer.parseInt(beginMonth)-1);
    	
    	Calendar calEnd = Calendar.getInstance();
    	calEnd.set(Calendar.YEAR,Integer.parseInt(endYear));
    	calEnd.set(Calendar.MONTH, Integer.parseInt(endMonth));
    	
    	List<String> lDate = new ArrayList<String>();  
    	/**加入开始时间，注意：20150就是201412需要判断
    	if(calBegin.get(Calendar.MONTH)==0){
    		int year = calBegin.get(Calendar.YEAR)-1;
    		int month = 12;
    		lDate.add(String.valueOf(year)+String.valueOf(month));
    	}else{
    		lDate.add(String.valueOf(calBegin.get(Calendar.YEAR))+String.valueOf(calBegin.get(Calendar.MONTH)));
    	}
    	*/
    	
    	 boolean bContinue = true;
    	 while (bContinue) {
    		 calBegin.add(Calendar.MONTH, 1);
    		 if(calEnd.after(calBegin)||calEnd.equals(calBegin)){
    			 
    			 if(calBegin.get(Calendar.MONTH)==0){
    		    		int year = calBegin.get(Calendar.YEAR)-1;
    		    		int month = 12;
    		    		lDate.add(String.valueOf(year)+String.valueOf(month));
    		    	}else{
    		    		lDate.add(String.valueOf(calBegin.get(Calendar.YEAR))+String.valueOf(calBegin.get(Calendar.MONTH)));
    		    	}
    		 }else{
    			 break;
    		 }
    	 }
    	 //加入结束时间
//    	 if(calEnd.get(Calendar.MONTH)==0){
//     		int year = calEnd.get(Calendar.YEAR)-1;
//     		int month = 12;
//     		lDate.add(String.valueOf(year)+String.valueOf(month));
//     	}else{
//     		lDate.add(String.valueOf(calEnd.get(Calendar.YEAR))+String.valueOf(calEnd.get(Calendar.MONTH)));
//     	}
        return lDate;  
    }
    
    /**
     * 根据开始和结束年份，算出之间的年list
     * @param beginYear
     * @param endYear
     * @return
     */
  public  List<String> getYearsBetweenTwoYear(String beginYear,String endYear) {  
    	
    	Calendar calBegin = Calendar.getInstance();
    	calBegin.set(Calendar.YEAR,Integer.parseInt(beginYear));
    	
    	Calendar calEnd = Calendar.getInstance();
    	calEnd.set(Calendar.YEAR,Integer.parseInt(endYear));
    	
    	List<String> lDate = new ArrayList<String>();  
    	//加入开始时间
    	lDate.add(String.valueOf(calBegin.get(Calendar.YEAR)));
    	
    	 boolean bContinue = true;
    	 while (bContinue) {
    		 calBegin.add(Calendar.YEAR, 1);
    		 if(calEnd.after(calBegin)||calEnd.equals(calBegin)){
    			 lDate.add(String.valueOf(calBegin.get(Calendar.YEAR)));
    		 }else{
    			 break;
    		 }
    	 }
    	 //加入结束时间
//    	 lDate.add(String.valueOf(calEnd.get(Calendar.YEAR)));
    	
        return lDate;  
    }
    
    
	/**
	 * 根据日期类型，时间段得出图表查询的参数值
	 * @param timeType_table
	 * @param timeType
	 * @param from
	 * @param to
	 * @return
	 * @throws ParseException
	 */
	@SuppressWarnings("deprecation")
	public HashMap<String, Object> getparam(String timeType_table,String timeType,String from,String to) throws ParseException{
		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
		HashMap<String, Object> resultMap = new HashMap<String, Object>();
		
		//根据日周月年查询不同的报表
		if(timeType_table.equals("hour")){
			resultMap.put("timeType_table", "hour");
			//根据timeType计算查询几天的数据
			if(timeType.equals("0")){
				Date dateFrom= sf.parse(from);
				Date dateTo= sf.parse(from);
				dateTo.setDate(dateTo.getDate()+1);
				resultMap.put("startDate",sf.format(dateFrom));
				resultMap.put("endDate", sf.format(dateTo));
			}else if(timeType.equals("1")){
				Date date=new Date();
				Date endDate=new Date();
				endDate.setDate(date.getDate()+1);
				String startDate=sf.format(date);
				resultMap.put("startDate", startDate);
				resultMap.put("endDate", sf.format(endDate));
			}else if(timeType.equals("2")){
				Date endDate = new Date();
				Date date=new Date();
				date.setDate(date.getDate()-1);
				String startDate=sf.format(date);
				resultMap.put("startDate", startDate);
				resultMap.put("endDate", sf.format(endDate));
			}
			//根据开始时间结束时间算出时间段
			List<String> listDate=getHoursBetweenTwoDate(resultMap.get("startDate").toString(),resultMap.get("endDate").toString());
			resultMap.put("Betweens", listDate);
		}else if(timeType_table.equals("day")){
			resultMap.put("timeType_table", "day");
			//根据timeType计算查询几天的数据
			if(timeType.equals("0")){
				Date dateFrom= sf.parse(from);
				Date dateTo= sf.parse(to);
				resultMap.put("startDate",sf.format(dateFrom));
				resultMap.put("endDate", sf.format(dateTo));
			}else if(timeType.equals("7")){
				Date date=new Date();
				String endDate=sf.format(date);
				date.setDate(date.getDate()-6);
				String startDate=sf.format(date);
				resultMap.put("startDate", startDate);
				resultMap.put("endDate", endDate);
			}else if(timeType.equals("14")){
				Date date=new Date();
				String endDate=sf.format(date);
				date.setDate(date.getDate()-13);
				String startDate=sf.format(date);
				resultMap.put("startDate", startDate);
				resultMap.put("endDate", endDate);
				
			}else if(timeType.equals("30")){
				Date date=new Date();
				String endDate=sf.format(date);
				date.setDate(date.getDate()-29);
				String startDate=sf.format(date);
				resultMap.put("startDate", startDate);
				resultMap.put("endDate", endDate);
			}else if(timeType.equals("1")){//当天1天
				resultMap.put("startDate",sf.format(new Date()));
				resultMap.put("endDate", sf.format(new Date()));
			}else if(timeType.equals("1_2")){//昨天1天
				Date date=new Date();
				date.setDate(date.getDate()-1);
				resultMap.put("startDate",sf.format(date));
				resultMap.put("endDate", sf.format(date));
			}
			//根据开始时间结束时间算出时间段
			List<String> listDate=getDatesBetweenTwoDate(resultMap.get("startDate").toString(),resultMap.get("endDate").toString());
			resultMap.put("Betweens", listDate);
		}else if(timeType_table.equals("week")){
			resultMap.put("timeType_table", "week");
			//根据timeType计算查询几周的数据
			if(timeType.equals("0")){
				Calendar clFrom = Calendar.getInstance(); 
				clFrom.setTime(sf.parse(from));
				clFrom.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); 
				Calendar clTo = Calendar.getInstance(); 
				clTo.setTime(sf.parse(to));
				clTo.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); 
				
				resultMap.put("startYear", clFrom.get(Calendar.YEAR));
				resultMap.put("endYear", clTo.get(Calendar.YEAR));
				resultMap.put("startWeek", clFrom.get(Calendar.WEEK_OF_YEAR));
				resultMap.put("endWeek", clTo.get(Calendar.WEEK_OF_YEAR));
				
			}else if(timeType.equals("4")){
				Calendar cl = Calendar.getInstance(); 
				cl.setTime(new Date());
				cl.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); 
				resultMap.put("endYear", cl.get(Calendar.YEAR));
				resultMap.put("endWeek", cl.get(Calendar.WEEK_OF_YEAR));
				cl.add(Calendar.WEEK_OF_YEAR, -3);
				cl.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); 
				resultMap.put("startYear", cl.get(Calendar.YEAR));
				resultMap.put("startWeek", cl.get(Calendar.WEEK_OF_YEAR));
				
				
			}else if(timeType.equals("8")){
				Calendar cl = Calendar.getInstance(); 
				cl.setTime(new Date());
				cl.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); 
				resultMap.put("endYear", cl.get(Calendar.YEAR));
				resultMap.put("endWeek", cl.get(Calendar.WEEK_OF_YEAR));
				cl.add(Calendar.WEEK_OF_YEAR, -7);
				cl.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); 
				resultMap.put("startYear", cl.get(Calendar.YEAR));
				resultMap.put("startWeek", cl.get(Calendar.WEEK_OF_YEAR));
				
			}else if(timeType.equals("12")){
				Calendar cl = Calendar.getInstance(); 
				cl.setTime(new Date());
				cl.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); 
				resultMap.put("endYear", cl.get(Calendar.YEAR));
				resultMap.put("endWeek", cl.get(Calendar.WEEK_OF_YEAR));
				cl.add(Calendar.WEEK_OF_YEAR, -11);
				cl.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); 
				resultMap.put("startYear", cl.get(Calendar.YEAR));
				resultMap.put("startWeek", cl.get(Calendar.WEEK_OF_YEAR));
			}
			
			if(resultMap.get("startWeek").toString().length()==1){
				resultMap.put("startWeek", "0"+resultMap.get("startWeek").toString());
			}
			if(resultMap.get("endWeek").toString().length()==1){
				resultMap.put("endWeek", "0"+resultMap.get("endWeek").toString());
			}
			
			//根据开始时间结束时间算出时间段
			List<String> listWeek=getWeeksBetweenTwoWeek(resultMap.get("startYear").toString(),resultMap.get("startWeek").toString(),
					resultMap.get("endYear").toString(),resultMap.get("endWeek").toString());
			resultMap.put("Betweens", listWeek);
			
			
		}else if(timeType_table.equals("month")){
			resultMap.put("timeType_table", "month");
			//根据timeType计算查询几月的数据
			if(timeType.equals("0")){
				Calendar clFrom = Calendar.getInstance(); 
				clFrom.setTime(sf.parse(from));
				Calendar clTo = Calendar.getInstance(); 
				clTo.setTime(sf.parse(to));
				
				resultMap.put("startYear", clFrom.get(Calendar.YEAR));
				resultMap.put("endYear", clTo.get(Calendar.YEAR));
				resultMap.put("startMonth", clFrom.get(Calendar.MONTH)+1);
				resultMap.put("endMonth", clTo.get(Calendar.MONTH)+1);
				
			}else if(timeType.equals("3")){
				Calendar cl = Calendar.getInstance(); 
				cl.setTime(new Date());
				resultMap.put("endYear", cl.get(Calendar.YEAR));
				resultMap.put("endMonth", cl.get(Calendar.MONTH)+1);
				cl.add(Calendar.MONTH, -2);
				resultMap.put("startYear", cl.get(Calendar.YEAR));
				resultMap.put("startMonth", cl.get(Calendar.MONTH)+1);
			}else if(timeType.equals("6")){
				Calendar cl = Calendar.getInstance(); 
				cl.setTime(new Date());
				resultMap.put("endYear", cl.get(Calendar.YEAR));
				resultMap.put("endMonth", cl.get(Calendar.MONTH)+1);
				cl.add(Calendar.MONTH, -5);
				resultMap.put("startYear", cl.get(Calendar.YEAR));
				resultMap.put("startMonth", cl.get(Calendar.MONTH)+1);
				
			}else if(timeType.equals("12")){
				Calendar cl = Calendar.getInstance(); 
				cl.setTime(new Date());
				resultMap.put("endYear", cl.get(Calendar.YEAR));
				resultMap.put("endMonth", cl.get(Calendar.MONTH)+1);
				cl.add(Calendar.MONTH, -11);
				resultMap.put("startYear", cl.get(Calendar.YEAR));
				resultMap.put("startMonth", cl.get(Calendar.MONTH)+1);
			}
			
			if(resultMap.get("startMonth").toString().length()==1){
				resultMap.put("startMonth", "0"+resultMap.get("startMonth").toString());
			}
			if(resultMap.get("endMonth").toString().length()==1){
				resultMap.put("endMonth", "0"+resultMap.get("endMonth").toString());
			}
			
			//根据开始时间结束时间算出时间段
			List<String> listMonth=getMonthsBetweenTwoMonth(resultMap.get("startYear").toString(),resultMap.get("startMonth").toString(),
					resultMap.get("endYear").toString(),resultMap.get("endMonth").toString());
			resultMap.put("Betweens", listMonth);
		
		}else{
			resultMap.put("timeType_table", "year");
			//根据timeType计算查询几年的数据
			if(timeType.equals("0")){
				
				Calendar clFrom = Calendar.getInstance(); 
				clFrom.setTime(sf.parse(from));
				Calendar clTo = Calendar.getInstance(); 
				clTo.setTime(sf.parse(to));
				
				resultMap.put("startYear", clFrom.get(Calendar.YEAR));
				resultMap.put("endYear", clTo.get(Calendar.YEAR));
				
			}else if(timeType.equals("3")){
				Calendar cl = Calendar.getInstance(); 
				cl.setTime(new Date());
				resultMap.put("endYear", cl.get(Calendar.YEAR));
				cl.add(Calendar.YEAR, -2);
				resultMap.put("startYear", cl.get(Calendar.YEAR));
			}else if(timeType.equals("5")){
				Calendar cl = Calendar.getInstance(); 
				cl.setTime(new Date());
				resultMap.put("endYear", cl.get(Calendar.YEAR));
				cl.add(Calendar.YEAR, -4);
				resultMap.put("startYear", cl.get(Calendar.YEAR));
				
			}
			
			//根据开始时间结束时间算出时间段
			List<String> listYear=getYearsBetweenTwoYear(resultMap.get("startYear").toString(),resultMap.get("endYear").toString());
			resultMap.put("Betweens", listYear);
			
			
		}
		return resultMap;
	}
	
	/**
	 * true 集团下面的所有广场=户权限下面的所有广场；false 集团下面的所有广场!=户权限下面的所有广场
	 */
	public boolean getJudgeAll(String siteId,UserInfo userInfo) throws Exception{
		//如果是集团的siteId ，1、查询集团下面的所有广场 2、查询用户权限下面的所有广场,如果权限的场所和集团下的场所相同，查询集团所有数据,如果权限的场所不同,查询权限广场的数据
		boolean judgeAll=true;//judgeAll=1 集团下面的所有广场=户权限下面的所有广场；judgeAll=0 集团下面的所有广场!=户权限下面的所有广场
		SiteAllInfo siteAllInfo=footfallGlobalMapper.selectSiteAllInfoById(siteId);
		if(siteAllInfo!=null){
			if(siteAllInfo.getType()!=null&&siteAllInfo.getType()==100){
				HashMap<String, Object> judgeMap=judgeParentIsAll(siteId,userInfo);
				String judge=judgeMap.get("judge").toString();
				if(judge!=null&&"0".equals(judge)){
					judgeAll=false;
				}
			}
		}
		return judgeAll;
	}
	/**
	 * 查询图表数据
	 * @param map
	 * @return List<ReportGraphData>
	 * @throws ParseException
	 */
	@SuppressWarnings("unchecked")
	public List<ReportGraphData> getGraphData(HashMap<String, Object> map)  throws Exception{
		List<ReportGraphData> resultList=new ArrayList<ReportGraphData>();
		//依据登陆用户信息查询用户场所
//		SiteAllInfo siteAllInfo=selectSiteByUserId((UserInfo)map.get("userInfo"));
		
		String timeType="";
		if(map.get("timeType")!=null && !map.get("timeType").toString().equals("")){
			timeType=map.get("timeType").toString();
		}
		String timeType_table="";
		if(map.get("timeType_table")!=null && !map.get("timeType_table").toString().equals("")){
			timeType_table=map.get("timeType_table").toString();
		}
		String from="";
		if(map.get("startDate")!=null && !map.get("startDate").toString().equals("")){
			from=map.get("startDate").toString();
		}
		String to="";
		if(map.get("endDate")!=null && !map.get("endDate").toString().equals("")){
			to=map.get("endDate").toString();
		}
		String type="";
		if(map.get("type")!=null && !map.get("type").toString().equals("")){
			type=map.get("type").toString();
		}
		String siteId="";
		if(map.get("siteId")!=null && !map.get("siteId").toString().equals("")){
			siteId=map.get("siteId").toString();
		}
		UserInfo userInfo=null;
		if(map.get("userInfo")!=null){
			userInfo=(UserInfo) map.get("userInfo");
		}
		                
		//如果是集团的siteId ，1、查询集团下面的所有广场 2、查询用户权限下面的所有广场,如果权限的场所和集团下的场所相同，查询集团所有数据,如果权限的场所不同,查询权限广场的数据
//		boolean judgeAll=getJudgeAll(siteId,userInfo);//judgeAll=1 集团下面的所有广场=户权限下面的所有广场；judgeAll=0 集团下面的所有广场!=户权限下面的所有广场
		
		/**
		 * 判断是不是集团场所
		 */
		boolean ifJituanSiteId = false;
		SiteAllInfo siteAllInfo=footfallGlobalMapper.selectSiteAllInfoById(siteId);
		if(siteAllInfo!=null){
			if(siteAllInfo.getType()!=null&&siteAllInfo.getType()==100){
				ifJituanSiteId = true;
			}
		}
		
		
		//根据日周月年的不同需要的参数map
		HashMap<String, Object> pramMap1=getparam(timeType_table,timeType,from,to);
		if(siteId.equals("")){
//			pramMap1.put("siteid",siteAllInfo.getSiteid());//放入场所id
		}else{
			pramMap1.put("siteid",siteId);//放入场所id
		}
		
		if(!"".equals(type)){
			 HashMap<String,Object> typeMap =getCalret(Integer.parseInt(type));
			 pramMap1.put("calret", typeMap.get("calret"));
			 pramMap1.put("ziduan", typeMap.get("ziduan"));
		}
		
		pramMap1.put("userId",userInfo.getUserId());
		
		if(pramMap1.get("timeType_table").equals("hour")){

			if(ifJituanSiteId){//如果是集团场所，要汇总集团下面的所有广场
//				resultList =footfallGlobalMapper.selectGraphDataHourJituanAll(pramMap1);//如果是集团汇总，集团下面所有的场所的汇总 = 有所有用户权限的；
				resultList =footfallGlobalMapper.selectPartGraphDataHour(pramMap1);
			}else{
				resultList =footfallGlobalMapper.selectGraphDataHour(pramMap1);	
			}
			
			/**和应该有的日期对比，如果该日期没有数据设置为空，添加到list  小时不预设 endit by wyp 20160406
			List<String> listDate=(List<String>)pramMap1.get("Betweens");
			if(resultList.size()!=listDate.size()){
				for (int da=0;da<listDate.size();da++){
					Boolean flg=false;
					for(int rep=0;rep< resultList.size();rep++){
						if(listDate.get(da).equals(resultList.get(rep).getDatatime())){
							flg=true;
						}
					}
					if(flg){
						continue;
					}else{
					ReportGraphData reportGraphData=new ReportGraphData();
					reportGraphData.setDatatime(listDate.get(da));
					reportGraphData.setDate(pramMap1.get("startDate").toString());
					reportGraphData.init();
					resultList.add(da, reportGraphData);
					}
				}
			}*/
		}else if(pramMap1.get("timeType_table").equals("day")){
			
			if(ifJituanSiteId){
//				resultList =footfallGlobalMapper.selectGraphDataDayJituanAll(pramMap1);//如果是集团汇总
				resultList =footfallGlobalMapper.selectPartGraphDataDay(pramMap1);
			}else{
				resultList =footfallGlobalMapper.selectGraphDataDay(pramMap1);
			}
		
			//和应该有的日期对比，如果该日期没有数据设置为空，添加到list
			List<String> listDate=(List<String>)pramMap1.get("Betweens");
			if(resultList.size()!=listDate.size()){
				for (int da=0;da<listDate.size();da++){
					Boolean flg=false;
					for(int rep=0;rep< resultList.size();rep++){
						if(listDate.get(da).equals(resultList.get(rep).getDatatime())){
							flg=true;
						}
					}
					if(flg){
						continue;
					}else{
					ReportGraphData reportGraphData=new ReportGraphData();
					reportGraphData.setDatatime(listDate.get(da));
					reportGraphData.init();
					resultList.add(da, reportGraphData);
					}
				}
			}
		}else if(pramMap1.get("timeType_table").equals("week")){
		
			if(ifJituanSiteId){
//					resultList =footfallGlobalMapper.selectGraphDataWeekJituanAll(pramMap1);//如果是集团汇总
				resultList =footfallGlobalMapper.selectPartGraphDataWeek(pramMap1);
			}else{
				resultList =footfallGlobalMapper.selectGraphDataWeek(pramMap1);
			}
			
			//和应该有的周对比，如果该周没有数据设置为空，添加到list
			List<String> listDate=(List<String>)pramMap1.get("Betweens");
			if(resultList.size()!=listDate.size()){
				for (int da=0;da<listDate.size();da++){
					Boolean flg=false;
					for(int rep=0;rep< resultList.size();rep++){
						if(listDate.get(da).equals(resultList.get(rep).getYear()+resultList.get(rep).getWeek())){
							flg=true;
						}
					}
					if(flg){
						continue;
					}else{
					ReportGraphData reportGraphData=new ReportGraphData();
					reportGraphData.setYear(listDate.get(da).substring(0,4));
					reportGraphData.setWeek(listDate.get(da).substring(4));
					reportGraphData.init();
					resultList.add(da, reportGraphData);
					}
				}
			}
		}else if(pramMap1.get("timeType_table").equals("month")){
			
			if(ifJituanSiteId){
//					resultList =footfallGlobalMapper.selectGraphDataMonthJituanAll(pramMap1);//如果是集团汇总
				resultList =footfallGlobalMapper.selectPartGraphDataMonth(pramMap1);
			}else{
				resultList =footfallGlobalMapper.selectGraphDataMonth(pramMap1);
			}
			
			//和应该有的月对比，如果该月没有数据设置为空，添加到list
			List<String> listDate=(List<String>)pramMap1.get("Betweens");
			if(resultList.size()!=listDate.size()){
				for (int da=0;da<listDate.size();da++){
					Boolean flg=false;
					for(int rep=0;rep< resultList.size();rep++){
						if(listDate.get(da).equals(resultList.get(rep).getYear()+resultList.get(rep).getMonth())){
							flg=true;
						}
					}
					if(flg){
						continue;
					}else{
					ReportGraphData reportGraphData=new ReportGraphData();
					reportGraphData.setYear(listDate.get(da).substring(0,4));
					reportGraphData.setMonth(listDate.get(da).substring(4));
					reportGraphData.init();
					resultList.add(da, reportGraphData);
					}
				}
			}
		}else{
			
				if(ifJituanSiteId){
//					resultList =footfallGlobalMapper.selectGraphDataYearJituanAll(pramMap1);//如果是集团汇总
					resultList =footfallGlobalMapper.selectPartGraphDataYear(pramMap1);
				}else{
					resultList =footfallGlobalMapper.selectGraphDataYear(pramMap1);
				}
			
			List<String> listDate=(List<String>)pramMap1.get("Betweens");
			if(resultList.size()!=listDate.size()){
				for (int da=0;da<listDate.size();da++){
					Boolean flg=false;
					for(int rep=0;rep< resultList.size();rep++){
						if(listDate.get(da).equals(resultList.get(rep).getYear())){
							flg=true;
						}
					}
					if(flg){
						continue;
					}else{
					ReportGraphData reportGraphData=new ReportGraphData();
					reportGraphData.setYear(listDate.get(da));
					reportGraphData.init();
					resultList.add(da, reportGraphData);
					}
				}
			}
		}
		return resultList;
	}
	
	/**
	 * @author wyp
	 * @param model
	 * @param index
	 * @return
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 */
	
	@SuppressWarnings("unused")
	public String getIndexData(Object model,String index) throws IllegalArgumentException, IllegalAccessException{
		String indexValue = "";
		Field[] fields=model.getClass().getDeclaredFields();
		for(Field field:fields){
			field.setAccessible(true);
			if(index.equals(field.getName())){
				indexValue = field.get(model).toString();	
			}
		}
		Field[] fieldsSuper=model.getClass().getSuperclass().getDeclaredFields();
		for(Field field:fieldsSuper){
			field.setAccessible(true);
			if(index.equals(field.getName())){
				indexValue = (field.get(model)==null)?"0":field.get(model).toString();	
			}
		}
//		保留两位小数
		if(indexValue.contains(".")){
			DecimalFormat df = new DecimalFormat("######0.00");
			double d = Double.parseDouble(indexValue);
			return df.format(d);
		}else{
			return indexValue;
		}
	}
	/**
	 * 设置属性为空
	 * @param model
	 * @param index
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 */
	private Object setIndexData(Object model,String index) throws IllegalArgumentException, IllegalAccessException{
		Field[] fields=model.getClass().getDeclaredFields();
		for(Field field:fields){
			field.setAccessible(true);
			if(index.equals(field.getName())){
				String type = field.getType().toString();//得到此属性的类型 
				if (type.endsWith("String")) { 
					field.set(model, "");
				}else if(type.endsWith("int") || type.endsWith("Integer")){
					field.set(model, 0);
				}
			}
		}
		Field[] fieldsSuper=model.getClass().getSuperclass().getDeclaredFields();
		for(Field field:fieldsSuper){
			field.setAccessible(true);
			if(index.equals(field.getName())){
				String type = field.getType().toString();//得到此属性的类型 
				if (type.endsWith("String")) { 
					field.set(model, "");
				}else if(type.endsWith("int") || type.endsWith("Integer")){
					field.set(model, 0);
				}
			}
		}
		return model;
	}
	
	
	public String getOrderFieldName(String orderFieldNum){
		String orderField = "";
		switch(Integer.parseInt(orderFieldNum)){
			case 0:orderField = "客流量";break;
			case 1:orderField = "集客力";break;
			case 2:orderField = "人效";break;
			case 3:orderField = "销售额";break;
			case 4:orderField = "提袋率";break;
			case 5:orderField = "客单价";break;
			case 6:orderField = "坪效";break;
			case 7:orderField = "顾客数";break;
			case 8:orderField = "平均游逛时间";break;
			case 9:orderField = "新顾客数";break;
			case 10:orderField = "老顾客数";break;
			case 11:orderField = "新顾客占比";break;
			case 12:orderField = "老顾客占比";break;
			case 13:orderField = "进店率";break;
			case 14:orderField = "返店率";break;
			case 15:orderField = "流失量";break;
			case 16:orderField = "流失率";break;
			case 17:orderField = "回流量";break;
			case 18:orderField = "回流率";break;
			case 19:orderField = "到访会员人数";break;
			case 20:orderField = "会员人数占比";break;
			case 21:orderField = "平均滞留时间";break;
			case 22:orderField = "滞留量";break;
			case 23:orderField = "出客流量";break;
			case 24:orderField = "活跃用户数";break;
			case 25:orderField = "活跃率";break;
			case 26:orderField = "沉默用户数";break;
			case 27:orderField = "沉默率";break;
			case 28:orderField = "存留量";break;
			case 29:orderField = "存留率";break;
			case 30:orderField = "上网人数";break;
			case 31:orderField = "新上网人数";break;
			case 32:orderField = "上网平均时长";break;
			case 33:orderField = "上网平均次数";break;
			case 34:orderField = "上网人数占比";break;
			case 35:orderField = "连接用户数";break;
			case 36:orderField = "新增连接用户数";break;
			case 37:orderField = "首次到店人数";break;
			case 38:orderField = "首次到店率";break;
			case 39:orderField = "wifi开启率";break;
			case 40:orderField = "历史用户数";break;
			case 41:orderField = "客流人次";break;
			case 42:orderField = "游逛深度";break;
			case 43:orderField = "会员总数";break;
			case 44:orderField = "服务能力";break;
			case 45:orderField = "交易笔数";break;
			case 46:orderField = "平均活跃天数";break;
			default:
				orderField = "";
				break;
		} 
		return orderField;
	}
	/**
	 * @author wyp
	 * 0= "客流量";1= "集客力";2= "人效";3= "销售额";4= "提袋率";
	 * 5= "客单价";6= "坪效";7= "顾客数";8= "平均游逛时间";9= "新顾客数";10= "老顾客数";11= "新顾客占比";
	 * 12= "老顾客占比";13= "进店率";14= "返店率";15= "流失量";16= "流失率";17= "回流量";18= "回流率";19= "会员人数";20= "会员人数占比";
	 * 21="平均滞留时间"
	 * @param orderFieldNum
	 * @return
	 */
	public String getOrderField(String orderFieldNum){
		String orderField = "";
		switch(Integer.parseInt(orderFieldNum)){
			case 0:orderField = "innum";break;
			case 1:orderField = "jkl";break;
			case 2:orderField = "posStaff";break;
			case 3:orderField = "pos";break;
			case 4:orderField = "rateBags";break;
			case 5:orderField = "posInnum";break;
			case 6:orderField = "posArea";break;
			case 7:orderField = "customerNum";break;
			case 8:orderField = "avgWanderTime";break;
			case 9:orderField = "newCustomerNum";break;
			case 10:orderField = "oldCustomer";break;
			case 11:orderField = "newCustomerPro";break;
			case 12:orderField = "oldCustomerPro";break;
			case 13:orderField = "inStoreRates";break;
			case 14:orderField = "returnStoreRates";break;
			case 15:orderField = "lossUserNum";break;
			case 16:orderField = "lossRates";break;
			case 17:orderField = "backUserNum";break;
			case 18:orderField = "backRates";break;
			case 19:orderField = "memNum";break;
			case 20:orderField = "memNumPro";break;
			case 21:orderField = "retentionavg";break;
			case 22:orderField = "retentionNum";break;
			case 23:orderField = "outnum";break;
			case 24:orderField = "activeUserNum";break;
			case 25:orderField = "activeRates";break;
			case 26:orderField = "silenceUserNum";break;
			case 27:orderField = "silenceRates";break;
			case 28:orderField = "stayUserNum";break;
			case 29:orderField = "stayRates";break;
			case 30:orderField = "interNum";break;
			case 31:orderField = "newInterNum";break;
			case 32:orderField = "interAvgDuration";break;
			case 33:orderField = "interAvgCount";break;
			case 34:orderField = "connectRates";break;
			case 35:orderField = "conUserNum";break;
			case 36:orderField = "newAddUserNum";break;
			case 37:orderField = "firstArrNum";break;
			case 38:orderField = "firstArrRates";break;
			case 39:orderField = "wifiOpenRate";break;
			case 40:orderField = "hisUserNum";break;
			case 41:orderField = "inCount";break;
			case 42:orderField = "wanderDepth";break;
			case 43:orderField = "memTotalNum";break;
			case 44:orderField = "serviceAbility";break;
			case 45:orderField = "posnum";break;
			case 46:orderField = "avgActDayNum";break;
			default:
				orderField = "";
				break;
		} 
		return orderField;
	}
	
	
	public String getChinaWeek(int weekInt){
		String weekStr="星期一";
		switch (weekInt) {
		case 1:
			weekStr="星期日";
			break;
		case 2:
			weekStr="星期一";
			break;
		case 3:
			weekStr="星期二";
			break;
		case 4:
			weekStr="星期三";
			break;
		case 5:
			weekStr="星期四";
			break;
		case 6:
			weekStr="星期五";
			break;
		case 7:
			weekStr="星期六";
			break;
		default:
			break;
		}
		return weekStr;
	}
	/**
	 * 数字千分位
	 * @param text
	 * @return
	 */
	public  String fmtMicrometer(String text)  
    {  
        DecimalFormat df = null;  
        if(text.indexOf(".") > 0)
        {  
            if(text.length() - text.indexOf(".")-1 == 0)  
            {  
                df = new DecimalFormat("###,##0.");  
            }else if(text.length() - text.indexOf(".")-1 == 1)  
            {  
                df = new DecimalFormat("###,##0.0");  
            }else  
            {  
                df = new DecimalFormat("###,##0.00");  
            }  
        }else   
        {  
            df = new DecimalFormat("###,##0");  
        }  
        double number = 0.0;  
        try {  
             number = Double.parseDouble(text);  
        } catch (Exception e) {  
            number = 0.0;  
        }  
        return df.format(number);  
    }
	/**前台获取图表数据  */
	public StringBuffer getGlobalTable(List<ReportGraphData> list,String timeType_table,UserInfo userInfo,String siteId) throws Exception {
		
		/**
		 * 更具时间类型、场所类型、用户、得到指标权限
		 * 我的数据-指标明细 moduleId=1_3;
		 */
		List<String> siteTypes = getSiteTypes(siteId);
		List<String> indexList = getUserIndex(userInfo);//用户指标权限
		String moduleId ="1_3";
		List<String>  indexPower  = getIndexListOfModel(indexList,moduleId,siteTypes);
		List<String> indexTimeList = getTimeIndex(timeType_table);//根据时间获取指标权限
		indexPower.retainAll(indexTimeList);
		
		//计算table列宽
		int rowNum = 2+indexPower.size();
		float rowWidth = 0;
		
		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
		StringBuffer stringTable=new StringBuffer();
		String thxingqi = "";
		if("day".equals(timeType_table)){
			rowWidth = (float) ((100-5.4)/(rowNum));
			thxingqi = "<th  style='width: "+rowWidth+"%;'>星期</th>";
		}else{
			rowWidth = (float) ((100-5.4)/(rowNum)-1);
			thxingqi = "";
		}
		stringTable.append("<table class='indextable xyliebiao widthall'>");
		stringTable.append("<tr><th class='xykongbai'></th>"
								+"<th class='xyxuhao'>编号</th>"
								+"<th  style='width: "+rowWidth+"%;'>日期</th>");
		stringTable.append(thxingqi);
		
		if (indexPower.contains("0")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>客流量（人次）</th>");
        }

        if (indexPower.contains("1")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>集客力（人/m2）</th>");
        }

        if (indexPower.contains("2")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>人效（元/人）</th>");
        }

        if (indexPower.contains("3")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>销售额（元）</th>");
        }

        if (indexPower.contains("4")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>提袋率（%）</th>");
        }

        if (indexPower.contains("5")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>客单价（元/人次）</th>");
        }

        if (indexPower.contains("6")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>坪效（元/m2）</th>");
        }

        if (indexPower.contains("7")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>顾客数（人）</th>");
        }

        if (indexPower.contains("8")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>平均游逛时间（min）</th>");
        }

        if (indexPower.contains("9")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>新顾客数（人）</th>");
        }

        if (indexPower.contains("10")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>老顾客数（人）</th>");
        }

        if (indexPower.contains("11")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>新顾客占比（%）</th>");
        }

        if (indexPower.contains("12")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>老顾客占比（%）</th>");
        }

        if (indexPower.contains("13")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>进店率（%）</th>");
        }

        if (indexPower.contains("14")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>返店率（%）</th>");
        }

        if (indexPower.contains("15")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>流失量（人）</th>");
        }

        if (indexPower.contains("16")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>流失率（%）</th>");
        }

        if (indexPower.contains("17")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>回流量（人）</th>");
        }

        if (indexPower.contains("18")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>回流率（%）</th>");
        }

        if (indexPower.contains("19")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>到访会员人数（人）</th>");
        }

        if (indexPower.contains("20")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>会员人数占比（%）</th>");
        }

        if (indexPower.contains("21")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>平均滞留时间（min）</th>");
        }

        if (indexPower.contains("22")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>滞留量（人次）</th>");
        }

        if (indexPower.contains("23")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>出客流量（人次）</th>");
        }

        if (indexPower.contains("24")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>活跃用户数（人）</th>");
        }

        if (indexPower.contains("25")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>活跃率（%）</th>");
        }

        if (indexPower.contains("26")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>沉默用户数（人）</th>");
        }

        if (indexPower.contains("27")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>沉默率（%）</th>");
        }

        if (indexPower.contains("28")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>存留量（人）</th>");
        }

        if (indexPower.contains("29")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>存留率（%）</th>");
        }

        if (indexPower.contains("30")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>上网人数（人）</th>");
        }

        if (indexPower.contains("31")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>新上网人数（人）</th>");
        }

        if (indexPower.contains("32")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>上网平均时长（min）</th>");
        }

        if (indexPower.contains("33")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>上网平均次数（次）</th>");
        }

        if (indexPower.contains("34")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>上网人数占比（%）</th>");
        }

        if (indexPower.contains("35")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>连接用户数（人）</th>");
        }

        if (indexPower.contains("36")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>新增连接用户数（人）</th>");
        }

        if (indexPower.contains("37")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>首次到店人数（人）</th>");
        }

        if (indexPower.contains("38")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>首次到店率（%）</th>");
        }

        if (indexPower.contains("39")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>wifi开启率（%）</th>");
        }

        if (indexPower.contains("40")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>历史用户数（人）</th>");
        }

        if (indexPower.contains("41")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>客流人次（人次）</th>");
        }

        if (indexPower.contains("42")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>游逛深度（/）</th>");
        }

        if (indexPower.contains("43")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>会员总数（人）</th>");
        }

        if (indexPower.contains("44")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>服务能力（人次/人）</th>");
        }

        if (indexPower.contains("45")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>交易笔数（笔）</th>");
        }

        if (indexPower.contains("46")) {
            stringTable.append("<th style='width: " + rowWidth +
                "%;'>平均活跃天数（天）</th>");
        }
		stringTable.append("<th class='xykongbai'></th></tr>");
		 for (int i = 0; i < list.size(); i++){
			String tdxingqi = "";
			String tdriqi = "";
			if("hour".equals(timeType_table)){
				tdxingqi = "";
				tdriqi = "<td>"+list.get(i).getDatatime()+"</td>";
			}else if("day".equals(timeType_table)){
				Calendar cl=Calendar.getInstance();
				cl.setTime(sf.parse(list.get(i).getDatatime()));
				int weekInt=cl.get(Calendar.DAY_OF_WEEK);
				tdxingqi = "<td>"+getChinaWeek(weekInt)+"</td>";
				tdriqi = "<td>"+list.get(i).getDatatime()+"</td>";
			}else if("week".equals(timeType_table)){
				tdxingqi = "";
				tdriqi = "<td>"+list.get(i).getYear()+"-"+list.get(i).getWeek()+"</td>";
			}else if("month".equals(timeType_table)){
				tdxingqi = "";
				tdriqi = "<td>"+list.get(i).getYear()+"-"+list.get(i).getMonth()+"</td>";
			}else{
				tdxingqi = "";
				tdriqi = "<td>"+list.get(i).getYear()+"</td>";
			}
			stringTable.append("<tr>");
			stringTable.append("<td class='xykongbai'></td>"
					+"<td class='xyxuhao'>"+(i + 1)+"</td>");
			stringTable.append(tdriqi);
			stringTable.append(tdxingqi);
			if (indexPower.contains("0")) {
	            stringTable.append("<td>" + fmtMicrometer(list.get(i).getInnum().toString()) +
	                "</td>");
	        }

	        if (indexPower.contains("1")) {
	            stringTable.append("<td>" + fmtMicrometer(list.get(i).getJkl()) +"</td>");
	        }

	        if (indexPower.contains("2")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getPosStaff()) + "</td>");
	        }

	        if (indexPower.contains("3")) {
	            stringTable.append("<td>" + fmtMicrometer(list.get(i).getPos()) +
	                "</td>");
	        }

	        if (indexPower.contains("4")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getRateBags()) + "</td>");
	        }

	        if (indexPower.contains("5")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getPosInnum()) + "</td>");
	        }

	        if (indexPower.contains("6")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getPosArea()) + "</td>");
	        }

	        if (indexPower.contains("7")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getCustomerNum()) + "</td>");
	        }

	        if (indexPower.contains("8")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getAvgWanderTime()) + "</td>");
	        }

	        if (indexPower.contains("9")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getNewCustomerNum()) + "</td>");
	        }

	        if (indexPower.contains("10")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getOldCustomer()) + "</td>");
	        }

	        if (indexPower.contains("11")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getNewCustomerPro()) + "</td>");
	        }

	        if (indexPower.contains("12")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getOldCustomerPro()) + "</td>");
	        }

	        if (indexPower.contains("13")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getInStoreRates()) + "</td>");
	        }

	        if (indexPower.contains("14")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getReturnStoreRates()) + "</td>");
	        }

	        if (indexPower.contains("15")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getLossUserNum()) + "</td>");
	        }

	        if (indexPower.contains("16")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getLossRates()) + "</td>");
	        }

	        if (indexPower.contains("17")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getBackUserNum()) + "</td>");
	        }

	        if (indexPower.contains("18")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getBackRates()) + "</td>");
	        }

	        if (indexPower.contains("19")) {
	            stringTable.append("<td>" + fmtMicrometer(list.get(i).getMemNum()) +
	                "</td>");
	        }

	        if (indexPower.contains("20")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getMemNumPro()) + "</td>");
	        }

	        if (indexPower.contains("21")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getRetentionavg()) + "</td>");
	        }

	        if (indexPower.contains("22")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getRetentionNum()) + "</td>");
	        }

	        if (indexPower.contains("23")) {
	            stringTable.append("<td>" + fmtMicrometer(list.get(i).getOutnum()) +
	                "</td>");
	        }

	        if (indexPower.contains("24")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getActiveUserNum()) + "</td>");
	        }

	        if (indexPower.contains("25")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getActiveRates()) + "</td>");
	        }

	        if (indexPower.contains("26")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getSilenceUserNum()) + "</td>");
	        }

	        if (indexPower.contains("27")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getSilenceRates()) + "</td>");
	        }

	        if (indexPower.contains("28")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getStayUserNum()) + "</td>");
	        }

	        if (indexPower.contains("29")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getStayRates()) + "</td>");
	        }

	        if (indexPower.contains("30")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getInterNum()) + "</td>");
	        }

	        if (indexPower.contains("31")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getNewInterNum()) + "</td>");
	        }

	        if (indexPower.contains("32")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getInterAvgDuration()) + "</td>");
	        }

	        if (indexPower.contains("33")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getInterAvgCount()) + "</td>");
	        }

	        if (indexPower.contains("34")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getConnectRates()) + "</td>");
	        }

	        if (indexPower.contains("35")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getConUserNum()) + "</td>");
	        }

	        if (indexPower.contains("36")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getNewAddUserNum()) + "</td>");
	        }

	        if (indexPower.contains("37")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getFirstArrNum()) + "</td>");
	        }

	        if (indexPower.contains("38")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getFirstArrRates()) + "</td>");
	        }

	        if (indexPower.contains("39")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getWifiOpenRate()) + "</td>");
	        }

	        if (indexPower.contains("40")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getHisUserNum()) + "</td>");
	        }

	        if (indexPower.contains("41")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getInCount()) + "</td>");
	        }

	        if (indexPower.contains("42")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getWanderDepth()) + "</td>");
	        }

	        if (indexPower.contains("43")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getMemTotalNum()) + "</td>");
	        }

	        if (indexPower.contains("44")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getServiceAbility()) + "</td>");
	        }

	        if (indexPower.contains("45")) {
	            stringTable.append("<td>" + fmtMicrometer(list.get(i).getPosnum()) +
	                "</td>");
	        }

	        if (indexPower.contains("46")) {
	            stringTable.append("<td>" +
	                fmtMicrometer(list.get(i).getAvgActDayNum()) + "</td>");
	        }
			stringTable.append("<td></td>"); 
			stringTable.append("</tr>");
         }
		 stringTable.append("</table>");
		return stringTable;
	}

	
	
	
	/**前台获取图表数据  */
	public StringBuffer getGlobalTable1(List<ReportGraphData> list,String timeType_table,UserInfo userInfo,String siteId) throws Exception {
		
		/**
		 * 更具时间类型、场所类型、用户、得到指标权限
		 * 我的数据-指标明细 moduleId=1_3;
		 */
		List<String> siteTypes = getSiteTypes(siteId);
		List<String> indexList = getUserIndex(userInfo);//用户指标权限
		String moduleId ="1_3";
		List<String>  indexPower  = getIndexListOfModel(indexList,moduleId,siteTypes);
		List<String> indexTimeList = getTimeIndex(timeType_table);//根据时间获取指标权限
		indexPower.retainAll(indexTimeList);
		List<String>  indexPo = new ArrayList<String>();
//		indexPo.add("0");
//		indexPo.add("1");
//		indexPower.retainAll(indexPo);
		//计算table列宽
		float rowWidth = 0;
		String rowWidthstr = "";
		float rowNum = 2+indexPower.size();
		
		SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
		StringBuffer stringTable=new StringBuffer();
		String thxingqi = "";
		if("day".equals(timeType_table)){
			rowNum =rowNum+1;
		}else{
			thxingqi = "";
		}
		if(rowNum<10&&rowNum>0){
			rowWidth = 1020/rowNum;
//			rowWidth = 100/rowNum;
//			rowWidthstr = Float.toString(rowWidth)+"%";
			rowWidthstr = Float.toString(rowWidth)+"px";
		}else{
			rowWidthstr ="130px";
		}
		if("day".equals(timeType_table)){
			thxingqi = "<th width="+rowWidthstr+">星期</th>";
		}else{
			thxingqi = "";
		}
		String tablewid ="";
		if(rowNum < 6){
			tablewid = "width='100%'";
		}
		
		stringTable.append("<table id='tabledata'  class='row-border stripe' "+tablewid+">");
		stringTable.append("<thead><tr><th width="+rowWidthstr+">编号</th>"
								+"<th width="+rowWidthstr+">日期</th>");
		stringTable.append(thxingqi);
		
		if (indexPower.contains("0")) {
            stringTable.append("<th  width=" + rowWidthstr + ">客流量（人次）</th>");
        }

        if (indexPower.contains("1")) {
            stringTable.append("<th  width=" + rowWidthstr + ">集客力（人/m2）</th>");
        }

        if (indexPower.contains("2")) {
            stringTable.append("<th  width=" + rowWidthstr + ">人效（元/人）</th>");
        }

        if (indexPower.contains("3")) {
            stringTable.append("<th  width=" + rowWidthstr + ">销售额（元）</th>");
        }

        if (indexPower.contains("4")) {
            stringTable.append("<th  width=" + rowWidthstr + ">提袋率（%）</th>");
        }

        if (indexPower.contains("5")) {
            stringTable.append("<th  width=" + rowWidthstr + ">客单价（元/人次）</th>");
        }

        if (indexPower.contains("6")) {
            stringTable.append("<th  width=" + rowWidthstr + ">坪效（元/m2）</th>");
        }

        if (indexPower.contains("7")) {
            stringTable.append("<th  width=" + rowWidthstr + ">顾客数（人）</th>");
        }

        if (indexPower.contains("8")) {
            stringTable.append("<th  width=" + rowWidthstr +
                ">平均游逛时间（min）</th>");
        }

        if (indexPower.contains("9")) {
            stringTable.append("<th  width=" + rowWidthstr + ">新顾客数（人）</th>");
        }

        if (indexPower.contains("10")) {
            stringTable.append("<th  width=" + rowWidthstr + ">老顾客数（人）</th>");
        }

        if (indexPower.contains("11")) {
            stringTable.append("<th  width=" + rowWidthstr + ">新顾客占比（%）</th>");
        }

        if (indexPower.contains("12")) {
            stringTable.append("<th  width=" + rowWidthstr + ">老顾客占比（%）</th>");
        }

        if (indexPower.contains("13")) {
            stringTable.append("<th  width=" + rowWidthstr + ">进店率（%）</th>");
        }

        if (indexPower.contains("14")) {
            stringTable.append("<th  width=" + rowWidthstr + ">返店率（%）</th>");
        }

        if (indexPower.contains("15")) {
            stringTable.append("<th  width=" + rowWidthstr + ">流失量（人）</th>");
        }

        if (indexPower.contains("16")) {
            stringTable.append("<th  width=" + rowWidthstr + ">流失率（%）</th>");
        }

        if (indexPower.contains("17")) {
            stringTable.append("<th  width=" + rowWidthstr + ">回流量（人）</th>");
        }

        if (indexPower.contains("18")) {
            stringTable.append("<th  width=" + rowWidthstr + ">回流率（%）</th>");
        }

        if (indexPower.contains("19")) {
            stringTable.append("<th  width=" + rowWidthstr + ">到访会员人数（人）</th>");
        }

        if (indexPower.contains("20")) {
            stringTable.append("<th  width=" + rowWidthstr + ">会员人数占比（%）</th>");
        }

        if (indexPower.contains("21")) {
            stringTable.append("<th  width=" + rowWidthstr +
                ">平均滞留时间（min）</th>");
        }

        if (indexPower.contains("22")) {
            stringTable.append("<th  width=" + rowWidthstr + ">滞留量（人次）</th>");
        }

        if (indexPower.contains("23")) {
            stringTable.append("<th  width=" + rowWidthstr + ">出客流量（人次）</th>");
        }

        if (indexPower.contains("24")) {
            stringTable.append("<th  width=" + rowWidthstr + ">活跃用户数（人）</th>");
        }

        if (indexPower.contains("25")) {
            stringTable.append("<th  width=" + rowWidthstr + ">活跃率（%）</th>");
        }

        if (indexPower.contains("26")) {
            stringTable.append("<th  width=" + rowWidthstr + ">沉默用户数（人）</th>");
        }

        if (indexPower.contains("27")) {
            stringTable.append("<th  width=" + rowWidthstr + ">沉默率（%）</th>");
        }

        if (indexPower.contains("28")) {
            stringTable.append("<th  width=" + rowWidthstr + ">存留量（人）</th>");
        }

        if (indexPower.contains("29")) {
            stringTable.append("<th  width=" + rowWidthstr + ">存留率（%）</th>");
        }

        if (indexPower.contains("30")) {
            stringTable.append("<th  width=" + rowWidthstr + ">上网人数（人）</th>");
        }

        if (indexPower.contains("31")) {
            stringTable.append("<th  width=" + rowWidthstr + ">新上网人数（人）</th>");
        }

        if (indexPower.contains("32")) {
            stringTable.append("<th  width=" + rowWidthstr +
                ">上网平均时长（min）</th>");
        }

        if (indexPower.contains("33")) {
            stringTable.append("<th  width=" + rowWidthstr + ">上网平均次数（次）</th>");
        }

        if (indexPower.contains("34")) {
            stringTable.append("<th  width=" + rowWidthstr + ">上网人数占比（%）</th>");
        }

        if (indexPower.contains("35")) {
            stringTable.append("<th  width=" + rowWidthstr + ">连接用户数（人）</th>");
        }

        if (indexPower.contains("36")) {
            stringTable.append("<th  width=" + rowWidthstr +
                ">新增连接用户数（人）</th>");
        }

        if (indexPower.contains("37")) {
            stringTable.append("<th  width=" + rowWidthstr + ">首次到店人数（人）</th>");
        }

        if (indexPower.contains("38")) {
            stringTable.append("<th  width=" + rowWidthstr + ">首次到店率（%）</th>");
        }

        if (indexPower.contains("39")) {
            stringTable.append("<th  width=" + rowWidthstr +
                ">wifi开启率（%）</th>");
        }

        if (indexPower.contains("40")) {
            stringTable.append("<th  width=" + rowWidthstr + ">历史用户数（人）</th>");
        }

        if (indexPower.contains("41")) {
            stringTable.append("<th  width=" + rowWidthstr + ">客流人次（人次）</th>");
        }

        if (indexPower.contains("42")) {
            stringTable.append("<th  width=" + rowWidthstr + ">游逛深度（/）</th>");
        }

        if (indexPower.contains("43")) {
            stringTable.append("<th  width=" + rowWidthstr + ">会员总数（人）</th>");
        }

        if (indexPower.contains("44")) {
            stringTable.append("<th  width=" + rowWidthstr +
                ">服务能力（人次/人）</th>");
        }

        if (indexPower.contains("45")) {
            stringTable.append("<th  width=" + rowWidthstr + ">交易笔数（笔）</th>");
        }

        if (indexPower.contains("46")) {
            stringTable.append("<th  width=" + rowWidthstr + ">平均活跃天数（天）</th>");
        }
        
        stringTable.append("</tr></thead><tbody>");
		 for (int i = 0; i < list.size(); i++){
			String tdxingqi = "";
			String tdriqi = "";
			if("hour".equals(timeType_table)){
				tdxingqi = "";
				tdriqi = "<td style='text-align:center'>"+list.get(i).getDatatime()+"</td>";
			}else if("day".equals(timeType_table)){
				Calendar cl=Calendar.getInstance();
				cl.setTime(sf.parse(list.get(i).getDatatime()));
				int weekInt=cl.get(Calendar.DAY_OF_WEEK);
				tdxingqi = "<td style='text-align:center'>"+getChinaWeek(weekInt)+"</td>";
				tdriqi = "<td style='text-align:center'>"+list.get(i).getDatatime()+"</td>";
			}else if("week".equals(timeType_table)){
				tdxingqi = "";
				tdriqi = "<td style='text-align:center'>"+list.get(i).getYear()+"-"+list.get(i).getWeek()+"</td>";
			}else if("month".equals(timeType_table)){
				tdxingqi = "";
				tdriqi = "<td style='text-align:center'>"+list.get(i).getYear()+"-"+list.get(i).getMonth()+"</td>";
			}else{
				tdxingqi = "";
				tdriqi = "<td style='text-align:center'>"+list.get(i).getYear()+"</td>";
			}
			stringTable.append("<tr>");
			stringTable.append("<td style='text-align:center' >"+(i + 1)+"</td>");
			stringTable.append(tdriqi);
			stringTable.append(tdxingqi);
			if (indexPower.contains("0")) {
	            stringTable.append("<td style='text-align:right'>" + fmtMicrometer(list.get(i).getInnum().toString()) +
	                "</td>");
	        }

	        if (indexPower.contains("1")) {
	            stringTable.append("<td style='text-align:right'>" + fmtMicrometer(list.get(i).getJkl()) +"</td>");
	        }

	        if (indexPower.contains("2")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getPosStaff()) + "</td>");
	        }

	        if (indexPower.contains("3")) {
	            stringTable.append("<td style='text-align:right'>" + fmtMicrometer(list.get(i).getPos()) +
	                "</td>");
	        }

	        if (indexPower.contains("4")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getRateBags()) + "</td>");
	        }

	        if (indexPower.contains("5")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getPosInnum()) + "</td>");
	        }

	        if (indexPower.contains("6")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getPosArea()) + "</td>");
	        }

	        if (indexPower.contains("7")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getCustomerNum()) + "</td>");
	        }

	        if (indexPower.contains("8")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getAvgWanderTime()) + "</td>");
	        }

	        if (indexPower.contains("9")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getNewCustomerNum()) + "</td>");
	        }

	        if (indexPower.contains("10")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getOldCustomer()) + "</td>");
	        }

	        if (indexPower.contains("11")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getNewCustomerPro()) + "</td>");
	        }

	        if (indexPower.contains("12")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getOldCustomerPro()) + "</td>");
	        }

	        if (indexPower.contains("13")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getInStoreRates()) + "</td>");
	        }

	        if (indexPower.contains("14")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getReturnStoreRates()) + "</td>");
	        }

	        if (indexPower.contains("15")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getLossUserNum()) + "</td>");
	        }

	        if (indexPower.contains("16")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getLossRates()) + "</td>");
	        }

	        if (indexPower.contains("17")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getBackUserNum()) + "</td>");
	        }

	        if (indexPower.contains("18")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getBackRates()) + "</td>");
	        }

	        if (indexPower.contains("19")) {
	            stringTable.append("<td style='text-align:right'>" + fmtMicrometer(list.get(i).getMemNum()) +
	                "</td>");
	        }

	        if (indexPower.contains("20")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getMemNumPro()) + "</td>");
	        }

	        if (indexPower.contains("21")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getRetentionavg()) + "</td>");
	        }

	        if (indexPower.contains("22")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getRetentionNum()) + "</td>");
	        }

	        if (indexPower.contains("23")) {
	            stringTable.append("<td style='text-align:right'>" + fmtMicrometer(list.get(i).getOutnum()) +
	                "</td>");
	        }

	        if (indexPower.contains("24")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getActiveUserNum()) + "</td>");
	        }

	        if (indexPower.contains("25")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getActiveRates()) + "</td>");
	        }

	        if (indexPower.contains("26")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getSilenceUserNum()) + "</td>");
	        }

	        if (indexPower.contains("27")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getSilenceRates()) + "</td>");
	        }

	        if (indexPower.contains("28")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getStayUserNum()) + "</td>");
	        }

	        if (indexPower.contains("29")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getStayRates()) + "</td>");
	        }

	        if (indexPower.contains("30")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getInterNum()) + "</td>");
	        }

	        if (indexPower.contains("31")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getNewInterNum()) + "</td>");
	        }

	        if (indexPower.contains("32")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getInterAvgDuration()) + "</td>");
	        }

	        if (indexPower.contains("33")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getInterAvgCount()) + "</td>");
	        }

	        if (indexPower.contains("34")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getConnectRates()) + "</td>");
	        }

	        if (indexPower.contains("35")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getConUserNum()) + "</td>");
	        }

	        if (indexPower.contains("36")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getNewAddUserNum()) + "</td>");
	        }

	        if (indexPower.contains("37")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getFirstArrNum()) + "</td>");
	        }

	        if (indexPower.contains("38")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getFirstArrRates()) + "</td>");
	        }

	        if (indexPower.contains("39")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getWifiOpenRate()) + "</td>");
	        }

	        if (indexPower.contains("40")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getHisUserNum()) + "</td>");
	        }

	        if (indexPower.contains("41")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getInCount()) + "</td>");
	        }

	        if (indexPower.contains("42")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getWanderDepth()) + "</td>");
	        }

	        if (indexPower.contains("43")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getMemTotalNum()) + "</td>");
	        }

	        if (indexPower.contains("44")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getServiceAbility()) + "</td>");
	        }

	        if (indexPower.contains("45")) {
	            stringTable.append("<td style='text-align:right'>" + fmtMicrometer(list.get(i).getPosnum()) +
	                "</td>");
	        }

	        if (indexPower.contains("46")) {
	            stringTable.append("<td style='text-align:right'>" +
	                fmtMicrometer(list.get(i).getAvgActDayNum()) + "</td>");
	        }
			stringTable.append("</tr>");
         }
		 stringTable.append("</tbody></table>");
		return stringTable;
	}
	
	/**
	 * 
	 * 根据日周年月，场所，字段获取排行榜数据
	 * @param HashMap<String, Object>
	 * @return List<RankingData>
	 * @author wenyp
	 */
	
	public List<RankingData> selectRankingByCondition(
			HashMap<String, Object> Map) throws Exception {
		
		PrivilegeUsersSite privilegeUsersSite=new PrivilegeUsersSite();
		SiteAllInfo siteAllInfo = null;
		if(Map.get("sitekey")!=null && !Map.get("sitekey").equals("")){
			privilegeUsersSite.setSitekey(Map.get("sitekey").toString());
			siteAllInfo=footfallGlobalMapper.selectSiteAllInfoByUsersSite(privilegeUsersSite);
		}else{
			return null;
		}
		
		
		
		if(siteAllInfo.getSiteid()!=null && !siteAllInfo.getSiteid().equals("")){
				Map.put("siteId", siteAllInfo.getSiteid().toString());
			}
		String type="";
		if(siteAllInfo.getType()!=null && !siteAllInfo.getType().equals("")){
				type= siteAllInfo.getType().toString();
			}	
		
		if(type.equals("100")){
			Map.put("field", "b.Parent100");
		}else if(type.equals("200")){
			Map.put("field", "b.Parent200");
		}else if(type.equals("300")){
			Map.put("field", "b.Parent300");
		}else if(type.equals("400")){
			Map.put("field", "b.Parent400");
		}else if(type.equals("500")){
			Map.put("field", "b.Parent500");
		}else if(type.equals("600")){
			Map.put("field", "b.Parent600");
		}else if(type.equals("700")){
			Map.put("field", "b.Parent1000");
		}
		List<RankingData> rankingData=new ArrayList<RankingData>();
		
		if(Map.get("timeType_table").equals("hour")){
			rankingData= footfallGlobalMapper.selectRankingDataHour(Map);
		}else if(Map.get("timeType_table").equals("day")){
			rankingData= footfallGlobalMapper.selectRankingDataDay(Map);
		}else if(Map.get("timeType_table").equals("week")){
			rankingData= footfallGlobalMapper.selectRankingDataWeek(Map);
		}else if(Map.get("timeType_table").equals("month")){
			rankingData= footfallGlobalMapper.selectRankingDataMonth(Map);
		}else{
			rankingData= footfallGlobalMapper.selectRankingDataYear(Map);
		}
		
		
		
		
		return rankingData;
	}
	/**
	 * 根据type获取指标计算公式
	 * @param int
	 * @return HashMap
	 * 
	 */
	public HashMap<String,Object> getCalret(int type){
		String calret = "";//统计的指标，客流，销额。。。
		String calretC = "";//统计的指标，客流，销额。。。
		String calretD = "";//统计的指标，客流，销额。。。
		String ziduan = "";//字段
		int isfloat = 0;//是否是浮点类型
		 switch (type)
         {
             case 0:
                 calret = "if(a.innum='' or a.innum is NULL,0,a.innum)";
                 calretC = "if(c.innum='' or c.innum is NULL,0,c.innum)";
                 calretD = "ifnull(sum(c.innum),0)";
                 ziduan = "innum";//客流量
                 break;
             case 1:
                 calret = "if(a.jkl='' or a.jkl is NULL,0,a.jkl)";
                 calretC =  "if(c.jkl='' or c.jkl is NULL,0,c.jkl)";
                 calretD =  "round(AVG(c.jkl),2) jkl";
                 ziduan = "jkl";//集客力
                 break;
             case 2:
                 calret = "round(ifnull(if(a.pos='' or a.pos is NULL,0,a.pos)/if(a.staffno='' or a.staffno is NULL,0,a.staffno),0),2)";
                 calretC =  "round(ifnull(if(c.pos='' or c.pos is NULL,0,c.pos)/if(c.staffno='' or c.staffno is NULL,0,c.staffno),0),2)";
                 calretD =  "round(sum(c.pos)/sum(c.staffno),2)";
                 ziduan = "posStaff";//人效
                 break;      
             case 3:
                 calret = "if(a.pos='' or a.pos is NULL,0,a.pos)";
                 calretC = "if(c.pos='' or c.pos is NULL,0,c.pos)";
                 calretD =  "ifnull(sum(c.pos),0)";
                 ziduan = "pos";//销售额
                 isfloat = 1;
                 break;
             case 4:
                 calret = "round(ifnull(if(a.posnum='' or a.posnum is NULL,0,a.posnum)*100/if(a.innum='' or a.innum is NULL,0,a.innum),0),2)";
                 calretC = "round(ifnull(if(c.posnum='' or c.posnum is NULL,0,c.posnum)*100/if(c.innum='' or c.innum is NULL,0,c.innum),0),2)";
                 calretD =  "round(sum(c.posnum)*100/sum(c.innum),2)";
                 ziduan = "rateBags";//提袋率
                 isfloat = 1;
                 break;
             case 5:
                 calret = "round(ifnull(if(a.pos='' or a.pos is NULL,0,a.pos)/if(a.innum='' or a.innum is NULL,0,a.innum),0),2)";
                 calretC = "round(ifnull(if(c.pos='' or c.pos is NULL,0,c.pos)/if(c.innum='' or c.innum is NULL,0,c.innum),0),2)";
                 calretD =  "round(sum(c.pos)/sum(c.innum),2)";
                 ziduan = "posInnum";//客单价pos/innum
                 isfloat = 1;
                 break;
             case 6:
                 calret = "round(ifnull(if(a.pos='' or a.pos is NULL,0,a.pos)/if(a.area='' or a.area is NULL,0,a.area),0),2)";
                 calretC = "round(ifnull(if(c.pos='' or c.pos is NULL,0,c.pos)/if(c.area='' or c.area is NULL,0,c.area),0),2)";
                 calretD =  "round(sum(c.pos)/sum(c.area),2)";
                 ziduan = "posArea";//坪效	pos/area
                 isfloat = 1;
                 break;
             case 21:
            	 calret = "if(a.retentionavg='' or a.retentionavg is NULL,0,a.retentionavg)";
            	 calretC = "if(c.retentionavg='' or c.retentionavg is NULL,0,c.retentionavg)";
                 calretD = "round(AVG(c.retentionavg),2)";
            	 ziduan = "retentionavg";
            	 break; 
             case 22:
            	 calret = "if(a.innum='' or a.innum is NULL,0,a.innum)-if(a.outnum='' or a.outnum is NULL,0,a.outnum)";
            	 calretC = "if(c.innum='' or c.innum is NULL,0,c.innum)-if(c.outnum='' or c.outnum is NULL,0,c.outnum)";
                 calretD = "ifnull(sum(c.innum-c.outnum),0)";
            	 ziduan = "retentionNum";
            	 break; 
             case 23:
            	 calret = "if(a.outnum='' or a.outnum is NULL,0,a.outnum)";
            	 calretC = "if(c.outnum='' or c.outnum is NULL,0,c.outnum)";
                 calretD = "ifnull(sum(c.outnum),0)";
            	 ziduan = "outnum";
            	 break; 
             case 7:
                 calret = "if(a.customerNum='' or a.customerNum is NULL,0,a.customerNum)";
                 calretC = "if(c.customerNum='' or c.customerNum is NULL,0,c.customerNum)";
                 calretD = "ifnull(sum(c.customerNum),0)";
                 ziduan = "customerNum"; //顾客数
                 break;
             case 9:
                 calret = "if(a.newCustomerNum='' or a.newCustomerNum is NULL,0,a.newCustomerNum)";
                 calretC = "if(c.newCustomerNum='' or c.newCustomerNum is NULL,0,c.newCustomerNum)";
                 calretD = "ifnull(sum(c.newCustomerNum),0)";
                 ziduan = "newCustomerNum"; //新顾客数
                 break;
             case 10:
                 calret = "if(a.oldCustomer='' or a.oldCustomer is NULL,0,a.oldCustomer)";
                 calretC = "if(c.oldCustomer='' or c.oldCustomer is NULL,0,c.oldCustomer)";
                 calretD = "ifnull(sum(c.oldCustomer),0)";
                 ziduan = "oldCustomer"; //老顾客数
                 break;
             case 11:
                 calret = "if(a.newCustomerPro='' or a.newCustomerPro is NULL,0,a.newCustomerPro)";
                 calretC = "if(c.newCustomerPro='' or c.newCustomerPro is NULL,0,c.newCustomerPro)";
                 calretD = "round(AVG(a.newCustomerPro),2)";
                 ziduan = "newCustomerPro"; //新顾客占比
                 break;
             case 12:
                 calret = "if(a.oldCustomerPro='' or a.oldCustomerPro is NULL,0,a.oldCustomerPro)";
                 calretC = "if(c.oldCustomerPro='' or c.oldCustomerPro is NULL,0,c.oldCustomerPro)";
                 calretD = "round(AVG(a.oldCustomerPro),2)";
                 ziduan = "oldCustomerPro"; //老顾客占比
                 break;
             case 14:
                 calret = "if(a.returnStoreRates='' or a.returnStoreRates is NULL,0,a.returnStoreRates)";
                 calretC = "if(c.returnStoreRates='' or c.returnStoreRates is NULL,0,c.returnStoreRates)";
                 calretD = "round(AVG(a.returnStoreRates),2),0)";
                 ziduan = "returnStoreRates"; //返店率
                 break;
             case 19:
                 calret = "if(a.memNum='' or a.memNum is NULL,0,a.memNum)";
                 calretC = "if(c.memNum='' or c.memNum is NULL,0,c.memNum)";
                 calretD = "ifnull(sum(c.memNum),0)";
                 ziduan = "memNum"; //会员人数
                 break;
             case 24:
                 calret = "if(a.activeUserNum='' or a.activeUserNum is NULL,0,a.activeUserNum)";
                 calretC = "if(c.activeUserNum='' or c.activeUserNum is NULL,0,c.activeUserNum)";
                 calretD = "ifnull(sum(c.activeUserNum),0)";
                 ziduan = "activeUserNum"; //活跃用户数
                 break;
             case 26:
                 calret = "if(a.silenceUserNum='' or a.silenceUserNum is NULL,0,a.silenceUserNum)";
                 calretC = "if(c.silenceUserNum='' or c.silenceUserNum is NULL,0,c.silenceUserNum)";
                 calretD = "ifnull(sum(c.silenceUserNum),0)";
                 ziduan = "silenceUserNum"; //沉默用户数
                 break;
             case 30:
                 calret = "if(a.interNum='' or a.interNum is NULL,0,a.interNum)";
                 calretC = "if(c.interNum='' or c.interNum is NULL,0,c.interNum)";
                 calretD = "ifnull(sum(c.interNum),0)";
                 ziduan = "interNum"; //上网人数
                 break;
             case 31:
                 calret = "if(a.newInterNum='' or a.newInterNum is NULL,0,a.newInterNum)";
                 calretC = "if(c.newInterNum='' or c.newInterNum is NULL,0,c.newInterNum)";
                 calretD = "ifnull(sum(c.newInterNum),0)";
                 ziduan = "newInterNum"; //新上网人数
                 break;
             case 32:
                 calret = "if(a.interAvgDuration='' or a.interAvgDuration is NULL,0,a.interAvgDuration)";
                 calretC = "if(c.interAvgDuration='' or c.interAvgDuration is NULL,0,c.interAvgDuration)";
                 calretD = "round(AVG(a.interAvgDuration),2)";
                 ziduan = "interAvgDuration"; //上网平均时长
                 break;
                 
             case 15:
                 calret = "if(a.lossUserNum='' or a.lossUserNum is NULL,0,a.lossUserNum) ";
                 calretC = "if(c.lossUserNum='' or c.lossUserNum is NULL,0,c.lossUserNum) ";
                 calretD = "ifnull(sum(c.lossUserNum),0)";
                 ziduan = "lossUserNum";
                 break;

             case 17:
                 calret = "if(a.backUserNum='' or a.backUserNum is NULL,0,a.backUserNum) ";
                 calretC = "if(c.backUserNum='' or c.backUserNum is NULL,0,c.backUserNum) ";
                 calretD = "ifnull(sum(c.backUserNum),0)";
                 ziduan = "backUserNum";
                 break;

             case 20:
                 calret = "if(a.memNumPro='' or a.memNumPro is NULL,0,a.memNumPro) ";
                 calretC = "if(c.memNumPro='' or c.memNumPro is NULL,0,c.memNumPro) ";
                 calretD = "round(AVG(a.memNumPro),2)";
                 ziduan = "memNumPro";
                 break;

             case 28:
                 calret = "if(a.stayUserNum='' or a.stayUserNum is NULL,0,a.stayUserNum) ";
                 calretC = "if(c.stayUserNum='' or c.stayUserNum is NULL,0,c.stayUserNum) ";
                 calretD = "ifnull(sum(c.stayUserNum),0)";
                 ziduan = "stayUserNum";
                 break;

             case 35:
                 calret = "if(a.conUserNum='' or a.conUserNum is NULL,0,a.conUserNum) ";
                 calretC = "if(c.conUserNum='' or c.conUserNum is NULL,0,c.conUserNum) ";
                 calretD = "ifnull(sum(c.conUserNum),0)";
                 ziduan = "conUserNum";
                 break;

             case 36:
                 calret = "if(a.newAddUserNum='' or a.newAddUserNum is NULL,0,a.newAddUserNum) ";
                 calretC = "if(c.newAddUserNum='' or c.newAddUserNum is NULL,0,c.newAddUserNum) ";
                 calretD = "ifnull(sum(c.newAddUserNum),0)";
                 ziduan = "newAddUserNum";
                 break;

             case 37:
                 calret = "if(a.firstArrNum='' or a.firstArrNum is NULL,0,a.firstArrNum) ";
                 calretC = "if(c.firstArrNum='' or c.firstArrNum is NULL,0,c.firstArrNum) ";
                 calretD = "ifnull(sum(c.firstArrNum),0)";
                 ziduan = "firstArrNum";
                 break;

             case 40:
                 calret = "if(a.hisUserNum='' or a.hisUserNum is NULL,0,a.hisUserNum) ";
                 calretC = "if(c.hisUserNum='' or c.hisUserNum is NULL,0,c.hisUserNum) ";
                 calretD = "ifnull(sum(c.hisUserNum),0)";
                 ziduan = "hisUserNum";
                 break;

             case 41:
                 calret = "if(a.inCount='' or a.inCount is NULL,0,a.inCount) ";
                 calretC = "if(c.inCount='' or c.inCount is NULL,0,c.inCount) ";
                 calretD = "ifnull(sum(c.inCount),0)";
                 ziduan = "inCount";
                 break;

             case 8:
                 calret = "if(a.avgWanderTime='' or a.avgWanderTime is NULL,0,a.avgWanderTime) ";
                 calretC = "if(c.avgWanderTime='' or c.avgWanderTime is NULL,0,c.avgWanderTime) ";
                 calretD = "round(AVG(c.avgWanderTime),2)";
                 ziduan = "avgWanderTime";
                 break;

             case 13:
                 calret = "if(a.inStoreRates='' or a.inStoreRates is NULL,0,a.inStoreRates) ";
                 calretC = "if(c.inStoreRates='' or c.inStoreRates is NULL,0,c.inStoreRates) ";
                 calretD = "round(AVG(c.inStoreRates),2)";
                 ziduan = "inStoreRates";
                 break;

             case 16:
                 calret = "if(a.lossRates='' or a.lossRates is NULL,0,a.lossRates) ";
                 calretC = "if(c.lossRates='' or c.lossRates is NULL,0,c.lossRates) ";
                 calretD = "round(AVG(c.lossRates),2)";
                 ziduan = "lossRates";
                 break;

             case 18:
                 calret = "if(a.backRates='' or a.backRates is NULL,0,a.backRates) ";
                 calretC = "if(c.backRates='' or c.backRates is NULL,0,c.backRates) ";
                 calretD = "round(AVG(c.backRates),2)";
                 ziduan = "backRates";
                 break;

             case 25:
                 calret = "if(a.activeRates='' or a.activeRates is NULL,0,a.activeRates) ";
                 calretC = "if(c.activeRates='' or c.activeRates is NULL,0,c.activeRates) ";
                 calretD = "round(AVG(c.activeRates),2)";
                 ziduan = "activeRates";
                 break;

             case 27:
                 calret = "if(a.silenceRates='' or a.silenceRates is NULL,0,a.silenceRates) ";
                 calretC = "if(c.silenceRates='' or c.silenceRates is NULL,0,c.silenceRates) ";
                 calretD = "round(AVG(c.silenceRates),2)";
                 ziduan = "silenceRates";
                 break;

             case 29:
                 calret = "if(a.stayRates='' or a.stayRates is NULL,0,a.stayRates) ";
                 calretC = "if(c.stayRates='' or c.stayRates is NULL,0,c.stayRates) ";
                 calretD = "round(AVG(c.stayRates),2)";
                 ziduan = "stayRates";
                 break;

             case 33:
                 calret = "if(a.interAvgCount='' or a.interAvgCount is NULL,0,a.interAvgCount) ";
                 calretC = "if(c.interAvgCount='' or c.interAvgCount is NULL,0,c.interAvgCount) ";
                 calretD = "round(AVG(c.interAvgCount),2)";
                 ziduan = "interAvgCount";
                 break;

             case 34:
                 calret = "if(a.connectRates='' or a.connectRates is NULL,0,a.connectRates) ";
                 calretC = "if(c.connectRates='' or c.connectRates is NULL,0,c.connectRates) ";
                 calretD = "round(AVG(c.connectRates),2)";
                 ziduan = "connectRates";
                 break;

             case 38:
                 calret = "if(a.firstArrRates='' or a.firstArrRates is NULL,0,a.firstArrRates) ";
                 calretC = "if(c.firstArrRates='' or c.firstArrRates is NULL,0,c.firstArrRates) ";
                 calretD = "round(AVG(c.firstArrRates),2)";
                 ziduan = "firstArrRates";
                 break;

             case 42:
                 calret = "if(a.wanderDepth='' or a.wanderDepth is NULL,0,a.wanderDepth) ";
                 calretC = "if(c.wanderDepth='' or c.wanderDepth is NULL,0,c.wanderDepth) ";
                 calretD = "round(AVG(c.wanderDepth),2)";
                 ziduan = "wanderDepth";
                 break;

             case 43:
                 calret = "if(a.memTotalNum='' or a.memTotalNum is NULL,0,a.memTotalNum) ";
                 calretC = "if(c.memTotalNum='' or c.memTotalNum is NULL,0,c.memTotalNum) ";
                 calretD = "round(AVG(c.memTotalNum),2)";
                 ziduan = "memTotalNum";
                 break;

             case 45:
            	 calret = "if(a.posnum='' or a.posnum is NULL,0,a.posnum) ";
                 calretC = "if(c.posnum='' or c.posnum is NULL,0,c.posnum) ";
                 calretD = "ifnull(sum(c.posnum),0)";
                 ziduan = "posnum";
                 break;
                 
             case 46:
                 calret = "if(a.avgActDayNum='' or a.avgActDayNum is NULL,0,a.avgActDayNum) ";
                 calretC = "if(c.avgActDayNum='' or c.avgActDayNum is NULL,0,c.avgActDayNum) ";
                 calretD = "round(AVG(c.avgActDayNum),2)";
                 ziduan = "avgActDayNum";
                 break;

             case 39:
                 calret = "round(ifnull(if(a.inCount='' or a.inCount is NULL,0,a.inCount)/if(a.innum='' or a.innum is NULL,0,a.innum),0),2)";
                 calretC = "round(ifnull(if(c.inCount='' or c.inCount is NULL,0,c.inCount)/if(c.innum='' or c.innum is NULL,0,c.innum),0),2) ";
                 calretD = "round(sum(c.inCount)/sum(c.innum),2)";
                 ziduan = "wifiOpenRate";
                 break;

             case 44:
                 calret = "round(ifnull(if(a.innum='' or a.innum is NULL,0,a.innum)/if(a.staffno='' or a.staffno is NULL,0,a.staffno),0),2)";
                 calretC = "round(ifnull(if(c.innum='' or c.innum is NULL,0,c.innum)/if(c.staffno='' or c.staffno is NULL,0,c.staffno),0),2)";
                 calretD = "round(sum(c.innum)/sum(c.staffno),2)";
                 ziduan = "serviceAbility";
                 break;
                 
             default: 
                calret = "ifnull(a.innum,0)";
                calretC = "if(c.innum='' or c.innum is NULL,0,c.innum)";
                calretD = "ifnull(sum(c.innum),0)";
                ziduan = "innum";
                break;	 
         }
		 HashMap<String,Object> map=new HashMap<String,Object>();
		 map.put("calret", calret);
		 map.put("calretC", calretC);
		 map.put("calretD", calretD);
		 map.put("ziduan", ziduan);
		 map.put("isfloat", isfloat);
		 
		return map;
		
	}
	
	public List<HashMap<String,Object>> getfootPaiHang(HashMap<String, Object> map)throws Exception {
		//获取位置
		String siteId="";
			if(map.get("siteId")==null ||map.get("siteId").equals("")){
				//依据登陆用户信息查询用户场所
//				SiteAllInfo siteAllInfo=selectSiteByUserId((UserInfo)map.get("userInfo"));
//				siteId=siteAllInfo.getSiteid();
			}else{
				siteId=map.get("siteId").toString();
			}
			//子场所类型
			String rankingType="";
			if(map.get("rankingType")!=null && map.get("rankingType").toString()!=""){
				rankingType=map.get("rankingType").toString();
			}
			
		//获取时间
			String timeType="";
			if(map.get("timeType")!=null && map.get("timeType").toString()!=""){
				timeType=map.get("timeType").toString();
			}
			String timeType_table="";
			if(map.get("timeType_table")!=null && map.get("timeType_table").toString()!=""){
				timeType_table=map.get("timeType_table").toString();
			}
			String from="";
			if(map.get("startDate")!=null && map.get("startDate").toString()!=""){
				from=map.get("startDate").toString();
			}
			String to="";
			if(map.get("endDate")!=null && map.get("endDate").toString()!=""){
				to=map.get("endDate").toString();
			}
			UserInfo userInfo=null;
			if(map.get("userInfo")!=null){
				userInfo=(UserInfo) map.get("userInfo");
			}
			String orderBy="";
			if(map.get("orderBy")!=null && map.get("orderBy").toString()!=""){
				orderBy=map.get("orderBy").toString();
			}
			
			//如果是集团的siteId ，1、查询集团下面的所有广场 2、查询用户权限下面的所有广场,如果权限的场所和集团下的场所相同，查询集团所有数据,如果权限的场所不同,查询权限广场的数据
			boolean judgeAll=true;//judgeAll=1 集团下面的所有广场=户权限下面的所有广场；judgeAll=0 集团下面的所有广场!=户权限下面的所有广场
			List<SiteAllInfo> partSiteAllInfoList=null;
			HashMap<String, String> siteIdMap=new HashMap<String, String>();
			SiteAllInfo siteAllInfo=footfallGlobalMapper.selectSiteAllInfoById(siteId);
			if(siteAllInfo!=null){
				if(siteAllInfo.getType()!=null&&siteAllInfo.getType()==100){
					HashMap<String, Object> judgeMap=judgeParentIsAll(siteId,userInfo);
					partSiteAllInfoList=(List<SiteAllInfo>) judgeMap.get("partSite");
					for(SiteAllInfo siteAllInfo1:partSiteAllInfoList){
						siteIdMap.put(siteAllInfo1.getSitename(),siteAllInfo1.getSiteid());
					}
					String judge=judgeMap.get("judge").toString();
					if(judge!=null&&"0".equals(judge)){//没有集团权限judge="0";
						judgeAll=false;
					}
				}
			}
			
		//获取要查询的指标
		int type=Integer.valueOf( (map.get("type").toString().split(","))[0]);
		//根据指标拼接要查询的字段
		HashMap<String, Object> CalretMap=getCalret(type);
		
		//根据日周月年的不同需要的参数map
		HashMap<String, Object> pramMap1=getparam(timeType_table,timeType,from,to);
		
		pramMap1.put("siteid",siteId);//放入场所id
		pramMap1.put("sitekey", siteId);
		pramMap1.put("calret", CalretMap.get("calret"));
		pramMap1.put("ziduan",CalretMap.get("ziduan"));
		String order = "DESC";
		if("1".equals(orderBy)){
			order = "DESC";
		}else{
			order = "ASC";
		}
		pramMap1.put("orderBy",order);
		
		//获取排行榜数据
		List<RankingData> rankingData=selectRankingByCondition(pramMap1);
		if(rankingData==null){
			return null;
		}
	
		
		
		//按照场所类型分类
		 List<List<RankingData>> rankingDataList=new ArrayList<List<RankingData>>();
		 List<RankingData> RankingData=new ArrayList<RankingData>();
		 List<RankingData> RankingData100=new ArrayList<RankingData>();
		 List<RankingData> RankingData200=new ArrayList<RankingData>();
		 List<RankingData> RankingData300=new ArrayList<RankingData>();
		 List<RankingData> RankingData400=new ArrayList<RankingData>();
		 List<RankingData> RankingData500=new ArrayList<RankingData>();
		 List<RankingData> RankingData600=new ArrayList<RankingData>();
		 List<RankingData> RankingData700=new ArrayList<RankingData>();
		 
		for(RankingData ranking :rankingData){
			ranking.getType();
			switch (ranking.getType())
	        {
	            case 100: 
	            	ranking.setTypename("集团");
	            	RankingData100.add(ranking);
	                break;
	            case 200: 
	            	ranking.setTypename("地区");
	            	RankingData200.add(ranking);
	                break;
	            case 300:
	                ranking.setTypename("广场");
	                RankingData300.add(ranking);
	                break;
	            case 400: 
	            	ranking.setTypename("区域");
	            	RankingData400.add(ranking);
	                break;
	            case 500: 
	            	ranking.setTypename("楼层");
	            	RankingData500.add(ranking);
	                break;
	            case 600: 
	            	ranking.setTypename("店铺");
	            	RankingData600.add(ranking);
	                break;
	            case 700:
	            	ranking.setTypename("通道");
	            	RankingData700.add(ranking);
	                break;
	            default:
	            	ranking.setTypename("根节点");
	            	RankingData.add(ranking);
	                break;
	        }
		}
		
		//全局去掉没有权限的场所排行
		List<String> rankingList=new ArrayList<String>();
		if(!judgeAll){//如果没有集团权限,删除没有权限的广场数据
			for(int i=RankingData300.size()-1;i>=0;i--){
				RankingData rankingData1= RankingData300.get(i);
				if(!siteIdMap.containsValue(rankingData1.getSitekey())){
					RankingData300.remove(rankingData1);
				}else{
					rankingList.add(rankingData1.getSitekey());//记录有权限广场
				}
			}
		}else{
			for(int i=RankingData300.size()-1;i>=0;i--){
				RankingData rankingData1= RankingData300.get(i);
				rankingList.add(rankingData1.getSitekey());//记录所有广场
			}
		}
		
//		如果集团没有查出来广场数据，而该用户有该广场权限再加进去
		Iterator iter = siteIdMap.entrySet().iterator();
		while (iter.hasNext()) {
			Map.Entry entry = (Map.Entry) iter.next(); 
			String key = (String) entry.getKey();
			String val = (String) entry.getValue();
			if(!rankingList.contains(val)){
				RankingData RankingDatatemp=new RankingData();
				RankingDatatemp.setSitekey(val);
				RankingDatatemp.setSitename(key);
				RankingData300.add(RankingDatatemp);
			};
		}	
		
		
		List<RankingData> Data=null;
		if(rankingType.equals("300")){
			Data=RankingData300;
		}else if(rankingType.equals("400")){
			Data=RankingData400;
		}else if(rankingType.equals("500")){
			Data=RankingData500;
		}else if(rankingType.equals("600")){
			Data=RankingData600;
		}else if(rankingType.equals("700")){
			Data=RankingData700;
		}else if(rankingType.equals("200")){
			Data=RankingData200;
		}
		
		List<HashMap<String,Object>> resultList = new ArrayList<HashMap<String,Object>>();
		HashMap<String,Object> changsuoData = new HashMap<String, Object>();
		List<RankingData> ranking=Data;
		changsuoData.put("siteType", ranking.get(0).getType());
		changsuoData.put("siteTypeName", ranking.get(0).getTypename());
		
		int i = 0;
		List<String> data = new ArrayList<String>();
		List<String> lable = new ArrayList<String>();
		List<String> lable1 = new ArrayList<String>();
		List<String> siteIds = new ArrayList<String>();
		List<String> siteNames = new ArrayList<String>();
		for(RankingData rankingData1 :ranking){
			data.add(getIndexData(rankingData1,getOrderField(Integer.toString(type))));
			lable.add(rankingData1.getSitename());
			lable1.add(String.valueOf(i+1));
			siteIds.add(rankingData1.getSitekey());
			siteNames.add(rankingData1.getSitename());
			i++;
		}
		
		String maxDate = "";
		if("1".equals(orderBy)){
			maxDate = getIndexData(ranking.get(0),getOrderField(Integer.toString(type)));
		}else{
			maxDate = getIndexData(ranking.get(ranking.size()-1),getOrderField(Integer.toString(type)));
			Collections.reverse(lable1);
		}
		double max = Double.parseDouble(maxDate)*10/8;
		changsuoData.put("maxDate",(int)max);
		
		changsuoData.put("data", data);
		changsuoData.put("lable", lable);
		changsuoData.put("lable1", lable1);
		changsuoData.put("siteIds", siteIds);
		changsuoData.put("siteNames", siteNames);
		resultList.add(changsuoData);
		
		
//		//百分比，最大显示80%，因此总的=最大*100/80
////		按照type拼接需要计算什么字段 ，人流，销售额。。。
//		float zong =0;
//		
//		if(type==0){
//			zong = Data.get(0).getInnum() * 10 / 8;
//		}else if(type==3){
//					zong = Float.parseFloat(Data.get(0).getPos()) * 10 / 8;
//		}
//		else if(type==4){
//			zong = Float.parseFloat(Data.get(0).getRateBags()) * 10 / 8;
//		}
//		else if(type==5){
//			zong = Float.parseFloat(Data.get(0).getPosInnum()) * 10 / 8;
//		}
//		else if(type==6){
//			zong = Float.parseFloat(Data.get(0).getPosArea()) * 10 / 8;
//		}
//		else if(type==1){
//			zong = Float.parseFloat(Data.get(0).getJkl()) * 10 / 8;
//		}
//		
//		
//		if(Data.get(0).getInnum()!=null){
//		zong = Data.get(0).getInnum() * 10 / 8;
//		}
//		
//		StringBuffer stringRank=new StringBuffer();
//		
//		for( int i=0; i<Data.size();i++){
//			float per=0;//数据条形图显示的比例
//			//如果是第一个per=80，其他为num/zong*100
//			
//			
//			if(type==0){
//				if(zong!=0){
//					if(i==0){per=80;
//					}else{
//					 per =(Data.get(i).getInnum()==null?0:Data.get(i).getInnum()) * 100 / zong;
//					}
//				}
//			}else if(type==3){
//				if(zong!=0){
//					if(i==0){per=80;
//					}else{
//					 per =Float.parseFloat((Data.get(i)==null?0:Data.get(i).getPos()).toString()) * 100 / zong;
//					}
//				}
//			}
//			else if(type==4){
//				if(zong!=0){
//					if(i==0){per=80;
//					}else{
//					 per =Float.parseFloat((Data.get(i)==null?0:Data.get(i).getRateBags()).toString()) * 100 / zong;
//					}
//				}
//			}
//			else if(type==5){
//				if(zong!=0){
//					if(i==0){per=80;
//					}else{
//					 per =Float.parseFloat((Data.get(i)==null?0:Data.get(i).getPosInnum()).toString()) * 100 / zong;
//					}
//				}
//			}
//			else if(type==6){
//				if(zong!=0){
//					if(i==0){per=80;
//					}else{
//					 per =Float.parseFloat((Data.get(i)==null?0:Data.get(i).getPosArea()).toString()) * 100 / zong;
//					}
//				}
//			}
//			else if(type==1){
//				if(zong!=0){
//					if(i==0){per=80;
//					}else{
//					 per =Float.parseFloat((Data.get(i)==null?0:Data.get(i).getJkl()).toString()) * 100 / zong;
//					}
//				}
//			}else{
//				if(zong!=0){
//					if(i==0){per=80;
//					}else{
//					 per =(Data.get(i)==null?0:Data.get(i).getInnum()) * 100 / zong;
//					}
//				}
//			}
//			
//			
//			String style = "";//显示5条其余的隐藏不显示，点击‘查看全部’显示全部。
//			if (i > 4)
//            {
//                style = "style='display:none'";
//            }
//			stringRank.append("<div class='shujuhang' "+style+">");
//			
////				stringRank.append("<div class='shujupaixu'>"+i+"</div>");
//				stringRank.append("<div class='shujuname'>");
//					
//				stringRank.append("<a >"+Data.get(i).getSitename()+"</a>");
//				stringRank.append("</div>");
//				
//				stringRank.append("<div class='shujutu'>");
//					stringRank.append("<div class='tiaoxingkuang'>");
//						stringRank.append("<div class='tiaoxing' style='width:"+per+"%'></div>");
//					stringRank.append("</div>");
//				stringRank.append("</div>");
//				
//				
////				按照type拼接需要计算什么字段 ，人流，销售额。。。
//				if(type==0){
//					stringRank.append("<div class='shujudata'>"+(Data.get(i).getInnum()==null?0:Data.get(i).getInnum())+"</div>");
//				}else if(type==3){
//					stringRank.append("<div class='shujudata'>"+(Data.get(i).getPos()==null?0:Data.get(i).getPos())+"</div>");
//				}
//				else if(type==4){
//					stringRank.append("<div class='shujudata'>"+(Data.get(i).getRateBags()==null?0:Data.get(i).getRateBags())+"</div>");
//				}
//				else if(type==5){
//					stringRank.append("<div class='shujudata'>"+(Data.get(i).getPosInnum()==null?0:Data.get(i).getPosInnum())+"</div>");
//				}
//				else if(type==6){
//					stringRank.append("<div class='shujudata'>"+(Data.get(i).getPosArea()==null?0:Data.get(i).getPosArea())+"</div>");
//				}
//				else if(type==1){
//					stringRank.append("<div class='shujudata'>"+(Data.get(i).getJkl()==null?0:Data.get(i).getJkl())+"</div>");
//				}
//				
//				
//				
//				stringRank.append("<div class='cleardiv'></div>");
//				
//			
//			stringRank.append("</div>");
//		}
//		if(Data.size()>5){
//			stringRank.append("<div id='divshowallRanking"+Data.get(0).getType()+"'  class='divshowallRanking' onclick='showAllRanking("+Data.get(0).getType()+")'>查看全部</div>");
//			}
		return resultList;
		
	}
	
	
	/**
	 * 查询排行榜数据
	 * @param map
	 * @return List<ReportGraphData>
	 * @throws ParseException
	 */
	@SuppressWarnings("unchecked")
	public List<HashMap<String,Object>> getRanking(HashMap<String, Object> map)
			throws Exception {
		//获取位置
		String siteId="";
			if(map.get("siteId")==null ||map.get("siteId").equals("")){
				//依据登陆用户信息查询用户场所
//				SiteAllInfo siteAllInfo=selectSiteByUserId((UserInfo)map.get("userInfo"));
//				siteId=siteAllInfo.getSiteid();
			}else{
				siteId=map.get("siteId").toString();
			}
			
		//获取时间
			String timeType="";
			if(map.get("timeType")!=null && map.get("timeType").toString()!=""){
				timeType=map.get("timeType").toString();
			}
			String timeType_table="";
			if(map.get("timeType_table")!=null && map.get("timeType_table").toString()!=""){
				timeType_table=map.get("timeType_table").toString();
			}
			String from="";
			if(map.get("startDate")!=null && map.get("startDate").toString()!=""){
				from=map.get("startDate").toString();
			}
			String to="";
			if(map.get("endDate")!=null && map.get("endDate").toString()!=""){
				to=map.get("endDate").toString();
			}
			UserInfo userInfo=null;
			if(map.get("userInfo")!=null){
				userInfo=(UserInfo) map.get("userInfo");
			}
			
			String orderBy="";
			if(map.get("orderBy")!=null && map.get("orderBy").toString()!=""){
				orderBy=map.get("orderBy").toString();
			}
			
			//如果是集团的siteId ，1、查询集团下面的所有广场 2、查询用户权限下面的所有广场,如果权限的场所和集团下的场所相同，查询集团所有数据,如果权限的场所不同,查询权限广场的数据
			boolean judgeAll=true;//judgeAll=1 集团下面的所有广场=户权限下面的所有广场；judgeAll=0 集团下面的所有广场!=户权限下面的所有广场
			List<SiteAllInfo> partSiteAllInfoList=null;
			HashMap<String, String> siteIdMap=new HashMap<String, String>();
			SiteAllInfo siteAllInfo=footfallGlobalMapper.selectSiteAllInfoById(siteId);
			if(siteAllInfo!=null){
				if(siteAllInfo.getType()!=null&&siteAllInfo.getType()==100){
					HashMap<String, Object> judgeMap=judgeParentIsAll(siteId,userInfo);
					partSiteAllInfoList=(List<SiteAllInfo>) judgeMap.get("partSite");
					for(SiteAllInfo siteAllInfo1:partSiteAllInfoList){
						siteIdMap.put(siteAllInfo1.getSitename(),siteAllInfo1.getSiteid());
					}
					String judge=judgeMap.get("judge").toString();
					if(judge!=null&&"0".equals(judge)){
						judgeAll=false;
					}
				}
			}
			
		//获取要查询的指标
		int type=Integer.valueOf( map.get("type").toString());
		//根据指标拼接要查询的字段
		HashMap<String, Object> CalretMap=getCalret(type);
		
		//根据日周月年的不同需要的参数map
		HashMap<String, Object> pramMap1=getparam(timeType_table,timeType,from,to);
		
		pramMap1.put("siteid",siteId);//放入场所id
		pramMap1.put("sitekey", siteId);
		pramMap1.put("calret", CalretMap.get("calret"));
		pramMap1.put("ziduan",CalretMap.get("ziduan"));
		
		String order = "DESC";
		if("1".equals(orderBy)){
			order = "DESC";
		}else{
			order = "DESC";
		}
		pramMap1.put("orderBy",order);
		
		
		//获取排行榜数据
		List<RankingData> rankingData=selectRankingByCondition(pramMap1);
		if(rankingData==null){
			return null;
		}
	
		
		
		//按照场所类型分类
		 List<List<RankingData>> rankingDataList=new ArrayList<List<RankingData>>();
		 List<RankingData> RankingData=new ArrayList<RankingData>();
		 List<RankingData> RankingData100=new ArrayList<RankingData>();
		 List<RankingData> RankingData200=new ArrayList<RankingData>();
		 List<RankingData> RankingData300=new ArrayList<RankingData>();
		 List<RankingData> RankingData400=new ArrayList<RankingData>();
		 List<RankingData> RankingData500=new ArrayList<RankingData>();
		 List<RankingData> RankingData600=new ArrayList<RankingData>();
		 List<RankingData> RankingData700=new ArrayList<RankingData>();
		 
		for(RankingData ranking :rankingData){
			ranking.getType();
			switch (ranking.getType())
	        {
	            case 100: 
	            	ranking.setTypename("集团");
	            	RankingData100.add(ranking);
	                break;
	            case 200: 
	            	ranking.setTypename("地区");
	            	RankingData200.add(ranking);
	                break;
	            case 300:
	                ranking.setTypename("广场");
	                RankingData300.add(ranking);
	                break;
	            case 400: 
	            	ranking.setTypename("区域");
	            	RankingData400.add(ranking);
	                break;
	            case 500: 
	            	ranking.setTypename("楼层");
	            	RankingData500.add(ranking);
	                break;
	            case 600: 
	            	ranking.setTypename("店铺");
	            	RankingData600.add(ranking);
	                break;
	            case 700:
	            	ranking.setTypename("通道");
	            	RankingData700.add(ranking);
	                break;
	            default:
	            	ranking.setTypename("根节点");
	            	RankingData.add(ranking);
	                break;
	        }
		}
		
		//全局去掉没有权限的场所排行
		List<String> rankingList=new ArrayList<String>();
		if(!judgeAll){//如果没有集团权限,删除没有权限的广场数据
			for(int i=RankingData300.size()-1;i>=0;i--){
				RankingData rankingData1= RankingData300.get(i);
				if(!siteIdMap.containsValue(rankingData1.getSitekey())){
					RankingData300.remove(rankingData1);
				}else{
					rankingList.add(rankingData1.getSitekey());//记录有权限广场
				}
			}
		}else{
			for(int i=RankingData300.size()-1;i>=0;i--){
				RankingData rankingData1= RankingData300.get(i);
				rankingList.add(rankingData1.getSitekey());//记录所有广场
			}
		}
		
//		如果集团没有查出来广场数据，而该用户有该广场权限再加进去
		Iterator iter = siteIdMap.entrySet().iterator();
		while (iter.hasNext()) {
			Map.Entry entry = (Map.Entry) iter.next(); 
			String key = (String) entry.getKey();
			String val = (String) entry.getValue();
			if(!rankingList.contains(val)){//测试代码需要修改为不包含
				RankingData RankingDatatemp=new RankingData();
				
				RankingDatatemp.setSitekey(val);
				RankingDatatemp.setSitename(key);
				RankingDatatemp.init();
				RankingData300.add(RankingDatatemp);
			};
		}	
		if(RankingData100.size()!=0){
		rankingDataList.add(RankingData100);
		}
		if(RankingData200.size()!=0){
			rankingDataList.add(RankingData200);
			}
		if(RankingData300.size()!=0){
			rankingDataList.add(RankingData300);
			}
		if(RankingData400.size()!=0){
			rankingDataList.add(RankingData400);
			}
		if(RankingData500.size()!=0){
			rankingDataList.add(RankingData500);
			}
		if(RankingData600.size()!=0){
			rankingDataList.add(RankingData600);
			}
		if(RankingData700.size()!=0){
			rankingDataList.add(RankingData700);
			}
		if(RankingData.size()!=0){
			rankingDataList.add(RankingData);
			}
		List<HashMap<String,Object>> resultList = new ArrayList<HashMap<String,Object>>();
		for(int rank=0;rank<rankingDataList.size();rank++){
			HashMap<String,Object> changsuoData = new HashMap<String, Object>();
			List<RankingData> ranking=rankingDataList.get(rank);
			Integer squrType = ranking.get(0).getType();//场所类型
			changsuoData.put("siteType", squrType);
			changsuoData.put("siteTypeName", ranking.get(0).getTypename());//场所名称
			/**
			 * 根据用户名和场所类型获取指标权限，得到没有指标权限的指标，将这些指标数值置空
			 */
			List<String> siteTypes = new ArrayList<String>();
			siteTypes.add(String.valueOf(squrType));
			List<String> indexList = getUserIndex(userInfo);
			String moduleId ="1_4";//排行榜是1_4
			List<String>  indexPower  = getIndexListOfModel(indexList,moduleId,siteTypes);
			List<String> indexTimeList = getTimeIndex(timeType_table);//根据时间获取指标权限
			indexPower.retainAll(indexTimeList);
			
			changsuoData.put("indexPower", indexPower);//有权限的指标
			List<String> indexNoPower = getIndexNoPower(indexPower);//没有权限的指标
			for(RankingData rankingData1 :ranking){
				for(String noindex:indexNoPower){
					String  noIndex = getOrderField(noindex);
					setIndexData(rankingData1,noIndex);//置空
				}
			}
			
			changsuoData.put("data", ranking);//数据
			resultList.add(changsuoData);
		}
		
		
		
		
		
		
		
//		List<HashMap<String,Object>> resultList = new ArrayList<HashMap<String,Object>>();
//		
//		for(int rank=0;rank<rankingDataList.size();rank++){
//			HashMap<String,Object> changsuoData = new HashMap<String, Object>();
//			List<RankingData> ranking=rankingDataList.get(rank);
//			changsuoData.put("siteType", ranking.get(0).getType());
//			changsuoData.put("siteTypeName", ranking.get(0).getTypename());
//			int i = 0;
//			List<String> data = new ArrayList<String>();
//			List<String> lable = new ArrayList<String>();
//			List<String> lable1 = new ArrayList<String>();
//			List<String> siteIds = new ArrayList<String>();
//			List<String> siteNames = new ArrayList<String>();
//			for(RankingData rankingData1 :ranking){
//				data.add(getIndexData(rankingData1,getOrderField(Integer.toString(type))));
//				lable.add(rankingData1.getSitename());
//				lable1.add(String.valueOf(i+1));
//				siteIds.add(rankingData1.getSitekey());
//				siteNames.add(rankingData1.getSitename());
//				i++;
//			}
//			String maxDate = "";
//			if("1".equals(orderBy)){
//				maxDate = getIndexData(ranking.get(0),getOrderField(Integer.toString(type)));
//			}else{
//				maxDate = getIndexData(ranking.get(ranking.size()-1),getOrderField(Integer.toString(type)));
//				Collections.reverse(lable1);
//			}
//			float max = Float.parseFloat(maxDate)*10/8;
//			changsuoData.put("maxDate",(int)max);
//			
//			changsuoData.put("data", data);
//			changsuoData.put("lable", lable);
//			changsuoData.put("lable1", lable1);
//			changsuoData.put("siteIds", siteIds);
//			changsuoData.put("siteNames", siteNames);
//			resultList.add(changsuoData);
//		}
//		
		
		
//		StringBuffer stringRank=new StringBuffer();
//		//拼接场所类型字符串
//			if(rankingDataList.get(rank).size()!=0){
//				List<RankingData>	Data=rankingDataList.get(rank);
//		//类型
//				stringRank.append("<div class='wid105 floatleft vercenter textcenter' id='Site_"+Data.get(0).getType()+"' onclick='getsite("+Data.get(0).getType()+")'>");
//				stringRank.append("<div class='font24 top36  outcsv'>"+Data.get(0).getTypename()+"</div>");
//				//第一个默认为选中状态
//				if(rank==0)
//				{
//					stringRank.append("<div class='left17 selectdiv selectedbar'");
//				}else{
//					stringRank.append("<div class='left17 selectdiv'");
//				}
//				stringRank.append("></div>");
//				stringRank.append("</div>");
////		stringRank.append("<li onclick='getsite("+Data.get(0).getType()+")' class='click' id='Site_"+Data.get(0).getType()+"'>"+Data.get(0).getTypename()+"</li>");
//		}
//			if(rank==rankingDataList.size()-1 ){
//			stringRank.append("\n");
//			}
//		}
//		//拼接类容字符串
//		for(int rank=0;rank<rankingDataList.size();rank++){
//		
//			if(rankingDataList.get(rank).size()!=0){
//				List<RankingData>	Data=rankingDataList.get(rank);
//			
//				
//		String	styleDiv = "";
//				
//		//类容
//		//如果不是第一个，DIV都设置为隐藏
//		if(rank!=0) styleDiv = "style='display:none'";
//		
//		stringRank.append("<div class='scollDiv' id='shuju_site"+Data.get(0).getType()+"'"+styleDiv+">");
//		
//		
//		
//		//百分比，最大显示80%，因此总的=最大*100/80
////		按照type拼接需要计算什么字段 ，人流，销售额。。。
//		float zong =0;
//		
//		if(type==0){
//			zong = (Data.get(0).getInnum()==null?0:Data.get(0).getInnum()) * 10 / 8;
//		}else if(type==3){
//			zong = Float.parseFloat((Data.get(0).getPos()==null||"".equals(Data.get(0).getPos())?"0":Data.get(0).getPos())) * 10 / 8;//Data.get(0).getPos()
//		}
//		else if(type==4){
//			zong = Float.parseFloat((Data.get(0).getRateBags()==null||"".equals(Data.get(0).getRateBags())?"0":Data.get(0).getRateBags())) * 10 / 8;//Data.get(0).getRateBags()
//		}
//		else if(type==5){
//			zong = Float.parseFloat((Data.get(0).getPosInnum()==null||"".equals(Data.get(0).getPosInnum())?"0":Data.get(0).getPosInnum())) * 10 / 8;//Data.get(0).getPosInnum()
//		}
//		else if(type==6){
//			zong = Float.parseFloat((Data.get(0).getPosArea()==null||"".equals(Data.get(0).getPosArea())?"0":Data.get(0).getPosArea())) * 10 / 8;//Data.get(0).getPosArea()
//		}
//		else if(type==1){
//			zong = Float.parseFloat((Data.get(0).getJkl()==null||"".equals(Data.get(0).getJkl())?"0":Data.get(0).getJkl())) * 10 / 8;
//		}
//		
//		
//		if(Data.get(0).getInnum()!=null){
//		zong = Data.get(0).getInnum() * 10 / 8;
//		}
//		
//		for( int i=0; i<Data.size();i++){
//			float per=0;//数据条形图显示的比例
//			//如果是第一个per=80，其他为num/zong*100
//			
//			
//			if(type==0){
//				if(zong!=0){
//					if(i==0){per=80;
//					}else{
//					 per =(Data.get(i).getInnum()==null?0:Data.get(i).getInnum()) * 100 / zong;
//					}
//				}
//			}else if(type==3){
//				if(zong!=0){
//					if(i==0){per=80;
//					}else{
//					 per =Integer.parseInt(Data.get(i).getPos()) * 100 / zong;
//					}
//				}
//			}
//			else if(type==4){
//				if(zong!=0){
//					if(i==0){per=80;
//					}else{
//					 per =Integer.parseInt(Data.get(i).getRateBags()) * 100 / zong;
//					}
//				}
//			}
//			else if(type==5){
//				if(zong!=0){
//					if(i==0){per=80;
//					}else{
//					 per =Integer.parseInt(Data.get(i).getPosInnum()) * 100 / zong;
//					}
//				}
//			}
//			else if(type==6){
//				if(zong!=0){
//					if(i==0){per=80;
//					}else{
//					 per =Integer.parseInt(Data.get(i).getPosArea()) * 100 / zong;
//					}
//				}
//			}
//			else if(type==1){
//				if(zong!=0){
//					if(i==0){per=80;
//					}else{
//					 per =Integer.parseInt(Data.get(i).getJkl()) * 100 / zong;
//					}
//				}
//			}else{
//				if(zong!=0){
//					if(i==0){per=80;
//					}else{
//					 per =Data.get(i).getInnum() * 100 / zong;
//					}
//				}
//			}
//			
//			
//			String style = "";//显示5条其余的隐藏不显示，点击‘查看全部’显示全部。
//			if (i > 4)
//            {
//                style = "style='display:none'";
//            }
//			stringRank.append("<div class='shujuhang' "+style+">");
//			
////				stringRank.append("<div class='shujupaixu'>"+i+"</div>");
//				stringRank.append("<div class='shujuname'>");
//					
//				stringRank.append("<a >"+Data.get(i).getSitename()+"</a>");
//				stringRank.append("</div>");
//				
//				stringRank.append("<div class='shujutu'>");
//					stringRank.append("<div class='tiaoxingkuang'>");
//						stringRank.append("<div class='tiaoxing' style='width:"+per+"%'></div>");
//					stringRank.append("</div>");
//				stringRank.append("</div>");
//				
//				
////				按照type拼接需要计算什么字段 ，人流，销售额。。。
//				if(type==0){
//					stringRank.append("<div class='shujudata'>"+Data.get(i).getInnum()+"</div>");
//				}else if(type==3){
//					stringRank.append("<div class='shujudata'>"+Data.get(i).getPos()+"</div>");
//				}
//				else if(type==4){
//					stringRank.append("<div class='shujudata'>"+Data.get(i).getRateBags()+"</div>");
//				}
//				else if(type==5){
//					stringRank.append("<div class='shujudata'>"+Data.get(i).getPosInnum()+"</div>");
//				}
//				else if(type==6){
//					stringRank.append("<div class='shujudata'>"+Data.get(i).getPosArea()+"</div>");
//				}
//				else if(type==1){
//					stringRank.append("<div class='shujudata'>"+Data.get(i).getJkl()+"</div>");
//				}
//				
//				
//				
//				stringRank.append("<div class='cleardiv'></div>");
//				
//			
//			stringRank.append("</div>");
//		}
//			
//		if(Data.size()>5){
//			stringRank.append("<div id='divshowallRanking"+Data.get(0).getType()+"'  class='divshowallRanking' onclick='showAllRanking("+Data.get(0).getType()+")'>查看全部</div>");
//			}
//		stringRank.append("</div>");
//		
//		}}
		
		return resultList;
	}
	
	/**
	 * @author
	 * @return void 
	 * @param UserSiteHistory
	 * 修改记录-用户访问记录siteId
	 * 
	 */
	public void updateUserSiteHistory(UserSiteHistory userSiteHistory){
		UserSiteHistory userSiteHistory1=userSiteHistoryMapper.selectBycondition(userSiteHistory);
		if(userSiteHistory1==null){
				userSiteHistory.setCreateTime(new Date());
				userSiteHistoryMapper.insert(userSiteHistory);
			}else {
				userSiteHistory.setId(userSiteHistory1.getId());
				userSiteHistory.setUpdateTime(new Date());
				userSiteHistory.setCreateTime(userSiteHistory1.getCreateTime());
				userSiteHistoryMapper.updateByPrimaryKeySelective(userSiteHistory);
			}
	}
	
	/**
	 * 查询历史
	 * @param userSiteHistory
	 * @return
	 */
	public UserSiteHistory selectUserSiteHistory(UserSiteHistory userSiteHistory){
		return userSiteHistoryMapper.selectBycondition(userSiteHistory);
		
	}
	
	/**
	 * 查询集团下面所有场所
	 * @param siteId
	 * @return
	 */
	
	public List<SiteAllInfo> selectSiteAllInforByparentId(String siteId){
		List<SiteAllInfo> SiteAllInfoList=new ArrayList<SiteAllInfo>();
		SiteAllInfoList=footfallGlobalMapper.selectSiteAllInforByparentId(siteId);
		return SiteAllInfoList;
	}
	
	/**
	 * 判断用户权限下面的场所是不是集团所有的场所
	 * @param siteId
	 * @param userInfo
	 * @return
	 * @throws Exception
	 */
	public HashMap<String, Object> judgeParentIsAll(String siteId,UserInfo userInfo) throws Exception{
		String judge="0";//没有集团权限
		List<SiteAllInfo> siteAll =loginService.getJtSiteList(userInfo);
		List<SiteAllInfo> siteAllInfoList1 =loginService.getGcSiteList(userInfo);
		//用户场所权限下面的场所属于同一个集团，因此只要比对site的数量就可以知道是不是全集
			if(siteAll!=null&&siteAll.size()!=0){
				judge="1";//有集团权限
			}
		HashMap<String, Object> resultMap=new HashMap<String, Object>();
		resultMap.put("partSite", siteAllInfoList1);
		resultMap.put("judge", judge);
		return resultMap;
		
	}
	/**
	 * 查询场所关系表获取上级集团的siteid
	 * @param sitekey
	 * @return
	 */
	
	public String selectSiteRelationByChildId(String sitekey){
		String result="";
		SiteRelation siteRelation=footfallGlobalMapper.selectSiteRelationByChildId(sitekey);
		if(siteRelation.getParent100()!=null&&!"".equals(siteRelation.getParent100())){
			result=siteRelation.getParent100();
		}else{
			result=siteRelation.getParent200();
		}
		return result;
	}
	
	/**
	 * 根据siteId获取sitename
	 * @param sitekey
	 * @return
	 */
	public String getSiteName(String sitekey){
		SiteAllInfo siteAllInfo=null;
		if(sitekey!=null&&!"".equals(sitekey)){
			siteAllInfo=footfallGlobalMapper.selectSiteAllInfoById(sitekey);
		}
		String siteName="";
		if(siteAllInfo!=null&&!"".equals(siteAllInfo.getSitename())){
			siteName=siteAllInfo.getSitename();
		}
		return siteName;
	}
	
	
	public SiteAllInfo getSiteAllInfo(String sitekey){
		SiteAllInfo siteAllInfo = null;
		if(sitekey!=null&&!"".equals(sitekey)){
			siteAllInfo=footfallGlobalMapper.selectSiteAllInfoById(sitekey);
		}
		return siteAllInfo;
	}
	
	public String getJituanIdByguangchangId(String siteID){
		
		SiteRelation siteRelation=footfallGlobalMapper.selectSiteRelationByChildId(siteID);
		String jituanSiteId = siteRelation.getParent100();
		return jituanSiteId;
		
	}
	
	
	/**
	 * 根据用户查询用户有权限的指标
	 * @param UserInfo
	 * @return
	 */
	public List<String> getUserIndex(UserInfo userInfo){
		List<WordBook>	WordBooks=null;
		List<String> result=new ArrayList<String>();
		if(userInfo!=null&&userInfo.getUserId()!=null&&!"".equals(userInfo.getUserId())){
//			WordBooks=footfallGlobalMapper.selectUserIndex(userInfo);
			WordBooks=footfallGlobalMapper.selectUserIndexV1(userInfo);
		}
		
		if(WordBooks!=null&&WordBooks.size()!=0){
			for(WordBook wordBook:WordBooks){
				result.add(wordBook.getDicCode());
			}
		}
		return result;
	}
	
	/**
	   * 在给定的元素中搜索指定的元素,返回符合条件的元素数组.对于不同级别的同名元素限制作用,即可以
	   * 搜索元素A中的子元素C.而对于元素B中子元素C则过虑,通过多级限定可以准确定位.
	   * @param parentElementString String
	   * @param tagName String
	   * @return String[]
	   */
	public  ArrayList<String[]> changeTableToList(String str){
		String[] trs =getElementsByTag(str,"tr");
		ArrayList<String[]> arrtr=new ArrayList<String[]>();
		
		for(String tr:trs){
			String[] tds;
			tds=getElementsByTag(tr,"td");
			if(tds.length==0){
				tds=getElementsByTag(tr,"th");
			}
			arrtr.add(tds);
		}
		return arrtr;
	}
	
	/**
	   * 在给定的元素中搜索指定的元素,返回符合条件的元素数组.对于不同级别的同名元素限制作用,即可以
	   * 搜索元素A中的子元素C.而对于元素B中子元素C则过虑,通过多级限定可以准确定位.
	   * @param parentElementString String
	   * @param tagName String
	   * @return String[]
	   */
	  private  String[] getElementsByTag(String parentElementString,String tagName){
	    Pattern p = Pattern.compile("<"+tagName+"[^>]*?>(.*?)(</"+tagName+">)|(/>)");
	    Matcher m = p.matcher(parentElementString);
	    ArrayList<String> al = new ArrayList<String>();
	    while(m.find())
	      al.add(m.group(1));
	    String[] arr = al.toArray(new String[al.size()]);
	    al.clear();
	    return arr;
	  }
	  
	  /**
		 * 根据场所type类型获取指标权限
		 * @param siteType
		 * @return
		 
		public List<String> getIndexPower(List<String> siteTypes){
			List<String> index = new ArrayList<String>();
			for(int i=0;i<22;i++){
				index.add(Integer.toString(i));
			}
			for(String siteType:siteTypes){
				List<String> indextemp = new ArrayList<String>();
				if("100".equals(siteType)){
					indextemp.add("0");//客流量
					indextemp.add("3");//销售额
					indextemp.add("7");//顾客数
				}else if("200".equals(siteType)){
					indextemp.add("0");//客流量
					indextemp.add("3");//销售额
					indextemp.add("7");//顾客数
				}else if("300".equals(siteType)){
					indextemp.add("0");//客流量
					indextemp.add("1");//集客力
					indextemp.add("2");//人效
					indextemp.add("3");//销售额
					indextemp.add("4");//提袋率
					indextemp.add("5");//客单价
					indextemp.add("6");//坪效
					indextemp.add("7");//顾客数
					indextemp.add("21");//平均滞留时间
				}else if("400".equals(siteType)){
					indextemp.add("0");//客流量
					indextemp.add("1");//集客力
					indextemp.add("3");//销售额
					indextemp.add("7");//顾客数
				}else if("500".equals(siteType)){
					indextemp.add("0");//客流量
					indextemp.add("1");//集客力
					indextemp.add("3");//销售额
			        indextemp.add("7");//顾客数
				}else if("600".equals(siteType)){
					indextemp.add("0");//客流量
					indextemp.add("1");//集客力
					indextemp.add("2");//人效
					indextemp.add("3");//销售额
					indextemp.add("4");//提袋率
					indextemp.add("5");//客单价
					indextemp.add("6");//坪效
					indextemp.add("7");//顾客数
					indextemp.add("21");//平均滞留时间
				}else if("700".equals(siteType)){
					indextemp.add("0");//客流量
				}
				index.retainAll(indextemp);
			}
			return index;
		}
		*/
		public  List<String> getIndexListOfModel(List<String> userIndex, String moduleId,
				List<String>  siteTypes){
			List<String>  resultIndex = userIndex;
			List<String>  Index = new ArrayList<String>();
			try {
				if(siteTypes != null&& !"".equals(siteTypes)){
					for(int i = 0;i<siteTypes.size();i++){
						String siteType = siteTypes.get(i);
						List<String>  indexTimeListOfSite = commonService.getIndexListOfModel(userIndex, moduleId, siteType);
						Index = getListJiaoji(indexTimeListOfSite,userIndex);
						resultIndex = getListJiaoji(resultIndex,Index);
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			//去重
			List<String> tempList= new ArrayList<String>();  
		    for(String i:resultIndex){  
		        if(!tempList.contains(i)){  
		            tempList.add(i);  
		        }  
		    }  
			return tempList;
		}
		
		
		public List<String> getTimeIndex(String timeType_table){
			List<String> indexTimeList = new ArrayList<String>();
			
			String dateType = "";
			if("hour".equals(timeType_table)){
				dateType = "1";
			}else if("day".equals(timeType_table)){
				dateType = "2";
			}else if("week".equals(timeType_table)){
				dateType = "3";
			}else if("month".equals(timeType_table)){
				dateType = "4";
			}else if("year".equals(timeType_table)){
				dateType = "5";
			}
			try {
				indexTimeList = commonService.getIndexListOfDate(dateType);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return indexTimeList;
		}
		
		
		
		/**
		 * 获取没有权限的指标
		 * @param siteTypes
		 * @return
		 */
		public List<String> getIndexNoPower(List<String> siteTypes){
			List<String> indextemp = new ArrayList<String>();
//			indextemp.add("0");//客流量
			for(int i = 0;i<47;i++){
				indextemp.add(Integer.toString(i));
			}
			
			
			
			for(int i=indextemp.size()-1;i>=0;i--){
				if(siteTypes.contains(indextemp.get(i))){
					indextemp.remove(i);
				}
			}
			return indextemp;
		}
		
		/**
		 * 根据siteid查询type
		 * @param siteId
		 * @return
		 */
		public List<String> getSiteTypes(String siteIds){
			List<String> indexs = new ArrayList<String>();
			String[] siteidstr = siteIds.split(",");
			for(String siteid:siteidstr){
				if(!"".equals(siteid)){
					SiteAllInfo siteAllInfo	= footfallGlobalMapper.selectSiteAllInfoById(siteid);
					indexs.add(siteAllInfo.getType().toString());
				}
			}
			//去重
			List<String> tempList= new ArrayList<String>();  
		    for(String i:indexs){  
		        if(!tempList.contains(i)){  
		            tempList.add(i);  
		        }  
		    }  
			return tempList;
		}
		
		/**
		 * 导航栏日期
		 * 当前时间：2015-11-16 下午 04:55
		 * @return
		 * @throws Exception
		
		@SuppressWarnings("deprecation")
		public String getDate() throws Exception{
			Date date=new Date();
			DateFormat format1=new SimpleDateFormat("yyyy-MM-dd hh:mm");
			String str=format1.format(date);
			String[] strs = str.split(" ");
			int hh=date.getHours();
			String restr = "";
			if(hh<12){
				restr="当前时间："+strs[0]+" 上午 "+strs[1];
			}
			else
			{
				restr="当前时间："+strs[0]+" 下午 "+strs[1];
			}
			return restr;
		} */
		/**
		 * 导航栏日期
		 * 当前时间：2015-11-16 下午
		 * @return
		 * @throws Exception
		 */
		@SuppressWarnings("deprecation")
		public String getDate() throws Exception{
			Date date=new Date();
			DateFormat format1=new SimpleDateFormat("yyyy-MM-dd");
			String str=format1.format(date);
			int hh=date.getHours();
			String restr = "";
			if(hh<12){
				restr="当前时间："+str+" 上午 ";
			}
			else
			{
				restr="当前时间："+str+" 下午 ";
			}
			return restr;
		}
		
		public List<String> getListJiaoji(List<String> list1,List<String> list2){
			List<String> resultList = new ArrayList<String>();
			for(int i = 0 ;i<list1.size();i++){
				if(list2.contains(list1.get(i))){
					resultList.add(list1.get(i));
				}
			}
			return resultList;
		}
		
		public String getSiteTypeName(Integer type ){
			String resultStr = "";
			switch (type)
	        {
	            case 100: 
	            	resultStr = "集团";
	                break;
	            case 200: 
	            	resultStr = "地区";
	                break;
	            case 300:
	                resultStr = "广场";
	                break;
	            case 400: 
	            	resultStr = "区域";
	                break;
	            case 500: 
	            	resultStr = "楼层";
	                break;
	            case 600: 
	            	resultStr = "店铺";
	                break;
	            case 700:
	            	resultStr = "通道";
	                break;
	            default:
	            	resultStr = "根节点";
	                break;
	        }
			return resultStr;
		}
		
		public HashMap<String, List<String>> getIndexListOfGroup(List<String> indexList){
			List<AllIndexModel> allIndexModels = footfallGlobalMapper.getIndexListOfGroup();
			List<AllIndexModel> fitIndexModels = new ArrayList<AllIndexModel>();
			for(AllIndexModel allIndexModel:allIndexModels){
				String indexTemp = allIndexModel.getIndex();
				if(indexList.contains(indexTemp)){
					fitIndexModels.add(allIndexModel);
				}
			}
			HashMap<String, List<String>> retMap = new HashMap<String, List<String>>();
			for(AllIndexModel fitIndexModel:fitIndexModels){
				String index = fitIndexModel.getIndex();
				String dataType = fitIndexModel.getDataType();
				if(retMap.containsKey(dataType)){
					List<String> indexs = retMap.get(dataType);
					indexs.add(index);
				}else{
					List<String> indexs = new ArrayList<String>();
					indexs.add(index);
					retMap.put(dataType, indexs);
				}
			}
			return retMap;
		}
		
		
		public HashMap<String, String> getIndexGroupInfo(){
			List<AllIndexModel> allIndexModels = footfallGlobalMapper.getIndexGroupInfo();
			HashMap<String, String> retMap = new HashMap<String, String>();
			for(AllIndexModel allIndexModel:allIndexModels){
				retMap.put(allIndexModel.getDataType(), allIndexModel.getDataTypeName());
			}
			
			
			
			return retMap;
	    	
	    }
		
		
		public HashMap<String, String> getIndexInfo(){
			List<AllIndexModel> allIndexModels = footfallGlobalMapper.getIndexInfo();
			HashMap<String, String> retMap = new HashMap<String, String>();
			for(AllIndexModel allIndexModel:allIndexModels){
				retMap.put(allIndexModel.getIndex(), allIndexModel.getIndexName());
			}
			
			return retMap;
		}
		
		public HashMap<String ,  List<String>> getIndexOrder(){
		   List<IndexOrderModel> IndexOrderModles = footfallGlobalMapper.getIndexOrder();
		   HashMap<String ,  List<String>> paraMap = new HashMap<String, List<String>>();
		   for(IndexOrderModel indexOrderModle:IndexOrderModles){
			  String dataType = indexOrderModle.getDataType();
			  List<String> dataTypeInMap = paraMap.get(dataType);
			  if(dataTypeInMap == null){
				  List<String> dataTypeInList = new ArrayList<String>(); 
				  dataTypeInList.add(indexOrderModle.getIndex());
				  paraMap.put(dataType, dataTypeInList);
			  }else{
				  dataTypeInMap.add(indexOrderModle.getIndex());
			  }
		   }
			return paraMap;
			
		}
		
		private String getIndexDanwei(String orderFieldNum){
			String orderField = "";
			switch(Integer.parseInt(orderFieldNum)){
				case 0:orderField = "人次";break;
				case 1:orderField = "人/m2";break;
				case 2:orderField = "元/人";break;
				case 3:orderField = "元";break;
				case 4:orderField = "%";break;
				case 5:orderField = "元/人次";break;
				case 6:orderField = "元/m2";break;
				case 7:orderField = "人";break;
				case 8:orderField = "min";break;
				case 9:orderField = "人";break;
				case 10:orderField = "人";break;
				case 11:orderField = "%";break;
				case 12:orderField = "%";break;
				case 13:orderField = "%";break;
				case 14:orderField = "%";break;
				case 15:orderField = "人";break;
				case 16:orderField = "%";break;
				case 17:orderField = "人";break;
				case 18:orderField = "%";break;
				case 19:orderField = "人";break;
				case 20:orderField = "%";break;
				case 21:orderField = "min";break;
				case 22:orderField = "人次";break;
				case 23:orderField = "人次";break;
				case 24:orderField = "人";break;
				case 25:orderField = "%";break;
				case 26:orderField = "人";break;
				case 27:orderField = "%";break;
				case 28:orderField = "人";break;
				case 29:orderField = "%";break;
				case 30:orderField = "人";break;
				case 31:orderField = "人";break;
				case 32:orderField = "min";break;
				case 33:orderField = "次";break;
				case 34:orderField = "%";break;
				case 35:orderField = "人";break;
				case 36:orderField = "人";break;
				case 37:orderField = "人";break;
				case 38:orderField = "%";break;
				case 39:orderField = "%";break;
				case 40:orderField = "人";break;
				case 41:orderField = "人次";break;
				case 42:orderField = "/";break;
				case 43:orderField = "人";break;
				case 44:orderField = "人次/人";break;
				case 45:orderField = "笔";break;
				case 46:orderField = "天";break;
				default:
					orderField = "";
					break;
			} 
			return orderField;
		}
		
		private String getTianqi(String Weather){
			String result = ""; 
			if("1".equals(Weather)){
				result ="晴";
			}else if("2".equals(Weather)){
				result ="阴";
			}else if("3".equals(Weather)){
				result ="雨";
			}else if("4".equals(Weather)){
				result ="雪";
			}else if("5".equals(Weather)){
				result ="沙尘";
			}else{
				result ="其他";
			}
			return result;
			
		}
		
		public String getTodayTargetStr(HashMap<String, Object> todayIndexes){
			
			Calendar now = Calendar.getInstance(); 
			TodayIndexes todayIndexes1=  (TodayIndexes) todayIndexes.get("todayIndexes");
			String  todayWeather =  todayIndexes1.getTodayWeather();
			String riqi = now.get(Calendar.YEAR)+"-"+(now.get(Calendar.MONTH) + 1)+"-"+now.get(Calendar.DAY_OF_MONTH);
			
			
			String lastDayWeather =  todayIndexes1.getLastDayWeather();
			now.add(Calendar.DATE,-1);//获取昨天 的日期
			String riqil = now.get(Calendar.YEAR)+"-"+(now.get(Calendar.MONTH) + 1)+"-"+now.get(Calendar.DAY_OF_MONTH);
			
			String lastWeekWeather = (String) todayIndexes1.getLastWeekWeather();
			Date datelw=new Date();
			now.add(Calendar.DATE,-6);//获取昨天 的日期
			String riqilw = now.get(Calendar.YEAR)+"-"+(now.get(Calendar.MONTH) + 1)+"-"+now.get(Calendar.DAY_OF_MONTH);
			
			StringBuffer resultSb = new StringBuffer();
			
			//头格式
			resultSb.append("<div class='floatleft ttjr whitediv em25'></div>"
			+"<div class='floatleft ttjg em25'></div>"
			+"<div class='floatleft ttzr whitediv em25'></div>"
			+"<div class='floatleft ttjg em25'></div>"
			+"<div class='floatleft ttzr whitediv em25'></div>"
			+"<div class='floatleft ttjr whitediv em14'></div>"
			+"<div class='floatleft ttjg em14'></div>"
			+"<div class='floatleft ttzr whitediv em14'></div>"
			+"<div class='floatleft ttjg em14'></div>"
			+"<div class='floatleft ttzr whitediv em14'></div>"
			);
			//今日天气
			resultSb.append("<div class='floatleft ttjr whitediv em36'><div class='ttjrlb'></div>" +
					"<div class='ttjrjg'></div><div class='ttjrzt'><div class='floatleft lineh36'><span class='font22'>今日" +
					"</span></div><div class='floatright lineh36'><img src='images/weather"+todayWeather+".png' " +
							"class='weatherimg vermiddle'/>&nbsp;&nbsp;<span><span id='todayWeather'>"+getTianqi(todayWeather)+"&nbsp;&nbsp;" +
									"</span><span>"+riqi+"</span></span></div></div><div class='ttjrjg'></div><div class='ttjrlb'></div></div>");
			//昨日天气
			
			resultSb.append("<div class='floatleft ttjg em36'></div><div class='floatleft ttzr whitediv em36'>" +
					"<div class='ttjrlb'></div><div class='ttjrjg'></div><div class='ttjrzt'><div class='floatleft lineh36'>" +
					"<span class='font22'>昨日</span></div><div class='floatright lineh36'>" +
					"<img src='images/weather"+lastDayWeather+".png' class='weatherimg vermiddle'/>&nbsp;&nbsp;<span>" +
							"<span id='lastDayWeather'>"+getTianqi(lastDayWeather)+"&nbsp;&nbsp;" +
									"</span><span>"+riqil+"</span></span></div></div><div class='ttjrjg'></div><div class='ttjrlb'></div></div>");
			//上周同日天气
			resultSb.append("<div class='floatleft ttjg em25'></div><div class='floatleft ttzr whitediv em36'>" +
					"<div class='ttjrlb'></div><div class='ttjrjg'></div><div class='ttjrzt'><div class='floatleft lineh36'>" +
					"<span class='font22'>上周同日</span></div><div class='floatright lineh36'>" +
					"<img src='images/weather"+lastWeekWeather+".png' class='weatherimg vermiddle'/>&nbsp;&nbsp;<span>" +
							"<span id='lastWeekWeather'>"+getTianqi(lastWeekWeather)+"&nbsp;&nbsp;" +
									"</span><span>"+riqilw+"</span></span></div></div><div class='ttjrjg'></div><div class='ttjrlb'></div></div>");
			
			//尾格式
			resultSb.append("<div class='floatleft ttjr whitediv em20'></div><div class='floatleft ttjg em20'>" +
					"</div><div class='floatleft ttzr whitediv em20'></div><div class='floatleft ttjg em20'></div>" +
					"<div class='floatleft ttzr whitediv em20'></div><div class='floatleft ttjr whitediv em5'>" +
					"<div class='ttjrlb'></div><div class='ttjrbar'></div><div class='ttjrlb'></div></div>" +
					"<div class='floatleft ttjg em5'></div><div class='floatleft ttzr whitediv em5'><div class='ttzrlb'>" +
					"</div><div class='ttzrbar'></div><div class='ttzrlb'></div></div><div class='floatleft ttjg em5'>" +
					"</div><div class='floatleft ttzr whitediv em5'><div class='ttzrlb'></div><div class='ttzrbar'>" +
					"</div><div class='ttzrlb'></div></div><div class='floatleft ttjr whitediv em25'></div>" +
					"<div class='floatleft ttjg em25'></div><div class='floatleft ttzr whitediv em25'></div>" +
					"<div class='floatleft ttjg em25'></div><div class='floatleft ttzr whitediv em25'></div>");
			
			//获取指标
			List<HashMap<String, Object>> indexDataLista=  (List<HashMap<String, Object>>) todayIndexes.get("indexDataList");
			for(int i =0;i<indexDataLista.size();i++){
				HashMap<String, Object> indexDataList = indexDataLista.get(i);
				String index = (String) indexDataList.get("indexNum");
				String indexName = getOrderFieldName(index);
				String indexDanwei = getIndexDanwei(index);
				String name = indexName+'/'+indexDanwei;
				TodayIndexes IndexesData =   (TodayIndexes) indexDataList.get("IndexesData");
				String dayData =  IndexesData.getDayData();
				String lastDayData =   IndexesData.getLastDayData();
				String lastWeekData =   IndexesData.getLastWeekData();
				String comLastDay =  (String) indexDataList.get("comLastDay");
				String comLastWeekDay =  (String) indexDataList.get("comLastWeekDay");
				resultSb.append("<div class='floatleft ttjr whitediv em75'><div class='ttjrlb'></div><div class='ttjrjg'></div><div class='ttjrzt'>"+
					"<div class='floatleft heigthall'><div class='ttname em25 lineh25'><span>"+name+"</span></div>"+
					"<div class='ttvalue em50 lineh50 selectcolor'><span>"+fmtMicrometer(dayData)+"</span></div>"+
					"</div><div class='floatright heigthall'><table class='indextable lineh75'><tr><td class='textL'>较昨日变化：</td>"+
					"<td class='textR selectcolor'>"+comLastDay+"%</td></tr><tr><td class='textL'>较上周同日变化：</td>"+
					"<td class='textR selectcolor'>"+comLastWeekDay+"%</td></tr></table></div></div><div class='ttjrjg'></div><div class='ttjrlb'></div>"+
					"</div><div class='floatleft ttjg em75'></div><div class='floatleft ttzr whitediv em75'><div class='ttzrlb'></div>"+
					"<div class='ttzrjg'></div><div class='ttzrzt'><div class='ttname em25 lineh25'><span>"+name+"</span></div>"+
					"<div class='ttvalue em50 lineh50'><span>"+fmtMicrometer(lastDayData)+"</span></div>"+
					"</div><div class='ttzrjg'></div><div class='ttzrlb'></div></div><div class='floatleft ttjg em75'></div>"+
					"<div class='floatleft ttzr whitediv em75'><div class='ttzrlb'></div><div class='ttzrjg'></div><div class='ttzrzt'>"+
					"<div class='ttname em25 lineh25'><span>"+name+"</span></div>"+
					"<div class='ttvalue em50 lineh50'><span>"+fmtMicrometer(lastWeekData)+"</span></div>"+
					"</div><div class='ttzrjg'></div><div class='ttzrlb'></div></div><div class='cleardiv'></div><div class='floatleft ttjr whitediv em25'></div>"+
					"<div class='floatleft ttjg em25'></div><div class='floatleft ttzr whitediv em25'></div><div class='floatleft ttjg em25'></div>"+
					"<div class='floatleft ttzr whitediv em25'></div>");
			}
			
			
			return resultSb.toString();
		}
		
		public String getSiteAllInfoById(String siteIds){
			
			StringBuffer ret = new StringBuffer();
			String[] siteidstr = siteIds.split(",");
			for(String siteid:siteidstr){
				if(!"".equals(siteid)){
					SiteAllInfo siteAllInfo	= footfallGlobalMapper.selectSiteAllInfoById(siteid);
					if(siteAllInfo == null){
						ret.append(siteid+"参数错误,");
					}
				}
			}
			return ret.toString();
		}
		
		/**前台获取图表数据  */
		@SuppressWarnings({"unchecked"})
		public StringBuffer getGlobalTable(List<HashMap<String, Object>> list,String timeType_table,String type) throws Exception {
			
			//计算table列宽
			int rowNum = list.size()-1;
			float rowWidth = 0;
			
			SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
			StringBuffer stringTable=new StringBuffer();
			StringBuffer stringTh=new StringBuffer();
			List<StringBuffer> stringTr=new ArrayList<StringBuffer>();
			
			stringTable.append("<table class='indextable xyliebiao widthall'  id=\"tableOut\">");
			if(timeType_table.equals("day")){
				
				rowWidth = (float) ((100-5.4)/(3+rowNum));
				stringTh.append("<tr><th class='xykongbai'></th><th class='xyxuhao'>序列</th><th style='width: "+rowWidth+"%;'>日期</th><th style='width: "+rowWidth+"%;'>星期</th>");
			}else{
				rowWidth = (float) ((100-5.4)/(2+rowNum));
				stringTh.append("<tr><th class='xykongbai'></th><th class='xyxuhao'>序列</th><th style='width: "+rowWidth+"%;'>日期</th>");
			}
			String indexName = getOrderField(type);
			int beak = 0;
			for(HashMap<String, Object> map:list){
				if(beak==0){
				stringTh.append("<th style='width: "+rowWidth+"%;'>"+map.get("siteName")+"</th>");
				List<ReportGraphData> data=(List<ReportGraphData>) map.get("data");
				for (int i = 0; i < data.size(); i++){
					String num="--";
					num=fmtMicrometer(getIndexData(data.get(i),indexName));
					String weekStr = "";
					String date = "";
					StringBuffer temp = new StringBuffer();
					if(timeType_table.equals("hour")){
						date = data.get(i).getDatatime();
						temp=new StringBuffer("<td class='xyxuhao'>"+(i + 1)+"</td><td>"+date+"</td><td>"+num+"</td>");
					}else if(timeType_table.equals("day")){
						Calendar cl=Calendar.getInstance();
						cl.setTime(sf.parse(data.get(i).getDatatime()));
						int weekInt=cl.get(Calendar.DAY_OF_WEEK);
						weekStr=getChinaWeek(weekInt);
						date = data.get(i).getDatatime();
						temp=new StringBuffer("<td class='xyxuhao'>"+(i + 1)+"</td><td>"+date+"</td><td>"+weekStr+"</td><td>"+num+"</td>");
					}else if(timeType_table.equals("week")){
						date = data.get(i).getYear()+"."+data.get(i).getWeek();
						temp=new StringBuffer("<td class='xyxuhao'>"+(i + 1)+"</td><td>"+date+"</td><td>"+num+"</td>");
					}else if(timeType_table.equals("month")){
						date = data.get(i).getYear()+"."+data.get(i).getMonth();
						temp=new StringBuffer("<td class='xyxuhao'>"+(i + 1)+"</td><td>"+date+"</td><td>"+num+"</td>");
					}else{
						date = data.get(i).getYear();
						temp=new StringBuffer("<td class='xyxuhao'>"+(i + 1)+"</td><td>"+date+"</td><td>"+num+"</td>");
					}
					stringTr.add(temp);
				}
				beak++;
				}else{
					stringTh.append("<th style='width: "+rowWidth+"%;'>"+map.get("siteName")+"</th>");
					List<ReportGraphData> data=(List<ReportGraphData>) map.get("data");
					for (int i = 0; i < data.size(); i++){
						String num="--";
						num=fmtMicrometer(getIndexData(data.get(i),indexName));
						StringBuffer temp=new StringBuffer("<td>"+num+"</td>");
						stringTr.get(i).append(temp);
			        }
				}
			beak++;
			}
			StringBuffer string=new StringBuffer();
			for(StringBuffer Str:stringTr){
				string=string.append("<tr><td class='xykongbai'></td>");
				string=string.append(Str);
				string=string.append("<td></td></tr>");
			}
			stringTh.append("<th class='xykongbai'></th></tr>");
			stringTable.append(stringTh);
			stringTable.append(string);
			stringTable.append("</table>");
			return stringTable;
		}
		

		
		public ReportGraphData getSiteMaxDataOfIndex(HashMap<String , Object> paraMap){
			HashMap<String, Object> pramMap1 = new HashMap<String, Object>();
			
			String siteId="";
			if(paraMap.get("siteId")!=null && !"".equals(paraMap.get("siteId").toString())){
				siteId = paraMap.get("siteId").toString();
			}
			pramMap1.put("siteid",siteId);
			
			String type = "";
			if(paraMap.get("type")!=null && !"".equals(paraMap.get("type").toString())){
				type = paraMap.get("type").toString();
			}
			String[] types = type.split(",");
			for(String ty : types){
				if(ty != null && !"".equals(ty)){
					 HashMap<String,Object> typeMap = getCalret(Integer.parseInt(ty));
					 pramMap1.put("calret"+ty, typeMap.get("calret"));
					 pramMap1.put("ziduan"+ty, typeMap.get("ziduan"));
				}
			}
			ReportGraphData reportGraphData =footfallGlobalMapper.selectMaxSitesData(pramMap1);	
			if(reportGraphData == null){
				ReportGraphData reportGraphDatatemp=new ReportGraphData();
				reportGraphDatatemp.init();
				reportGraphData = reportGraphDatatemp;
			}
			return reportGraphData;
		}
		
		
}
